From 35cd7332ab62072a0a3d81c7e259a64ad5a61ba8 Mon Sep 17 00:00:00 2001 From: Jamie Madill Date: Sun, 2 Dec 2018 12:03:33 -0500 Subject: [PATCH] Refactor test shader style. This change enforces a lot more consistency. We pass const char * to the Compile functions instead of std::string. Also fixes the indentation of C++11 block comments to be more consistent. Bug: angleproject:2995 Change-Id: Id6e5ea94055d8cbd420df4ea2e81b2d96cb5ce78 Reviewed-on: https://chromium-review.googlesource.com/c/1357103 Reviewed-by: Jamie Madill Commit-Queue: Jamie Madill --- samples/hello_triangle/HelloTriangle.cpp | 48 +- samples/mip_map_2d/MipMap2D.cpp | 75 +- samples/multi_texture/MultiTexture.cpp | 78 +- samples/multi_window/MultiWindow.cpp | 77 +- .../MultipleDrawBuffers.cpp | 42 +- samples/multiview/Multiview.cpp | 24 +- samples/particle_system/ParticleSystem.cpp | 95 +- samples/post_sub_buffer/PostSubBuffer.cpp | 62 +- samples/sample_util/SampleApplication.cpp | 28 +- samples/sample_util/SampleApplication.h | 4 +- .../simple_instancing/SimpleInstancing.cpp | 71 +- samples/simple_texture_2d/SimpleTexture2D.cpp | 70 +- .../SimpleTextureCubemap.cpp | 52 +- .../SimpleVertexShader.cpp | 60 +- .../stencil_operations/StencilOperations.cpp | 111 +- .../TexRedefMicroBench.cpp | 138 +- samples/texture_wrap/TextureWrap.cpp | 96 +- .../tri_fan_microbench/TriFanMicroBench.cpp | 106 +- src/tests/BUILD.gn | 5 +- .../EGLIOSurfaceClientBufferTest.cpp | 6 +- .../egl_tests/EGLPresentPathD3D11Test.cpp | 6 +- .../egl_tests/EGLProgramCacheControlTest.cpp | 9 +- src/tests/egl_tests/EGLStreamTest.cpp | 6 +- src/tests/egl_tests/EGLSurfaceTest.cpp | 22 +- .../gl_tests/AtomicCounterBufferTest.cpp | 26 +- src/tests/gl_tests/AttributeLayoutTest.cpp | 6 +- .../gl_tests/BPTCCompressedTextureTest.cpp | 36 +- .../gl_tests/BindUniformLocationTest.cpp | 96 +- src/tests/gl_tests/BlendFuncExtendedTest.cpp | 26 +- .../gl_tests/BlitFramebufferANGLETest.cpp | 4 +- src/tests/gl_tests/BufferDataTest.cpp | 68 +- src/tests/gl_tests/BuiltinVariableTest.cpp | 10 +- src/tests/gl_tests/ClearTest.cpp | 6 +- src/tests/gl_tests/ClientArraysTest.cpp | 4 +- src/tests/gl_tests/ComputeShaderTest.cpp | 1392 ++++++------ .../gl_tests/CopyCompressedTextureTest.cpp | 10 +- src/tests/gl_tests/CopyTexImageTest.cpp | 6 +- src/tests/gl_tests/CopyTexture3DTest.cpp | 91 +- src/tests/gl_tests/CopyTextureTest.cpp | 18 +- .../gl_tests/D3D11InputLayoutCacheTest.cpp | 4 +- .../gl_tests/D3DImageFormatConversionTest.cpp | 34 +- src/tests/gl_tests/D3DTextureTest.cpp | 10 +- .../gl_tests/DXT1CompressedTextureTest.cpp | 36 +- .../gl_tests/DXTSRGBCompressedTextureTest.cpp | 10 +- .../gl_tests/DepthStencilFormatsTest.cpp | 44 +- src/tests/gl_tests/DrawBuffersTest.cpp | 8 +- src/tests/gl_tests/DrawElementsTest.cpp | 14 +- .../gl_tests/FloatingPointSurfaceTest.cpp | 4 +- .../gl_tests/FramebufferMultiviewTest.cpp | 24 +- src/tests/gl_tests/FramebufferTest.cpp | 70 +- src/tests/gl_tests/GLSLTest.cpp | 2003 ++++++++--------- src/tests/gl_tests/GeometryShaderTest.cpp | 470 ++-- src/tests/gl_tests/ImageTest.cpp | 17 +- src/tests/gl_tests/IncompleteTextureTest.cpp | 46 +- src/tests/gl_tests/IndexBufferOffsetTest.cpp | 6 +- src/tests/gl_tests/IndexedPointsTest.cpp | 65 +- src/tests/gl_tests/InstancingTest.cpp | 12 +- src/tests/gl_tests/LinkAndRelinkTest.cpp | 75 +- src/tests/gl_tests/MaxTextureSizeTest.cpp | 48 +- src/tests/gl_tests/MipmapTest.cpp | 173 +- src/tests/gl_tests/MultiviewDrawTest.cpp | 169 +- src/tests/gl_tests/PBOExtensionTest.cpp | 47 +- src/tests/gl_tests/PackUnpackTest.cpp | 69 +- .../gl_tests/ParallelShaderCompileTest.cpp | 6 +- src/tests/gl_tests/PathRenderingTest.cpp | 26 +- src/tests/gl_tests/PbufferTest.cpp | 6 +- src/tests/gl_tests/PointSpritesTest.cpp | 135 +- src/tests/gl_tests/ProgramBinaryTest.cpp | 48 +- src/tests/gl_tests/ProgramInterfaceTest.cpp | 104 +- src/tests/gl_tests/ProvokingVertexTest.cpp | 7 +- src/tests/gl_tests/ReadPixelsTest.cpp | 6 +- .../RobustBufferAccessBehaviorTest.cpp | 6 +- src/tests/gl_tests/RobustResourceInitTest.cpp | 43 +- src/tests/gl_tests/SRGBTextureTest.cpp | 6 +- .../gl_tests/ShaderStorageBufferTest.cpp | 121 +- src/tests/gl_tests/SimpleOperationTest.cpp | 115 +- src/tests/gl_tests/SixteenBppTextureTest.cpp | 40 +- src/tests/gl_tests/StateChangeTest.cpp | 25 +- src/tests/gl_tests/SwizzleTest.cpp | 40 +- src/tests/gl_tests/TextureMultisampleTest.cpp | 49 +- src/tests/gl_tests/TextureRectangleTest.cpp | 8 +- src/tests/gl_tests/TextureTest.cpp | 634 +++--- src/tests/gl_tests/TimerQueriesTest.cpp | 12 +- src/tests/gl_tests/TransformFeedbackTest.cpp | 259 +-- src/tests/gl_tests/UniformBufferTest.cpp | 106 +- src/tests/gl_tests/UniformTest.cpp | 104 +- src/tests/gl_tests/UnpackAlignmentTest.cpp | 14 +- src/tests/gl_tests/UnpackRowLength.cpp | 14 +- src/tests/gl_tests/VertexAttributeTest.cpp | 22 +- src/tests/gl_tests/WebGLCompatibilityTest.cpp | 176 +- .../WebGLReadOutsideFramebufferTest.cpp | 8 +- src/tests/perf_tests/ANGLEPerfTest.cpp | 3 +- src/tests/perf_tests/BindingPerf.cpp | 2 + src/tests/perf_tests/DispatchComputePerf.cpp | 29 +- .../perf_tests/DynamicPromotionPerfTest.cpp | 6 +- src/tests/perf_tests/InstancingPerf.cpp | 6 +- .../perf_tests/InterleavedAttributeData.cpp | 6 +- src/tests/perf_tests/MultiviewPerf.cpp | 10 +- src/tests/perf_tests/PointSprites.cpp | 2 +- src/tests/perf_tests/TexSubImage.cpp | 34 +- src/tests/perf_tests/TextureSampling.cpp | 2 +- src/tests/perf_tests/TexturesPerf.cpp | 2 +- src/tests/perf_tests/UniformsPerf.cpp | 4 +- src/tests/test_utils/ANGLETest.cpp | 81 +- src/tests/test_utils/ANGLETest.h | 1 - src/tests/test_utils/MultiviewTest.cpp | 4 +- src/tests/test_utils/draw_call_perf_utils.cpp | 69 +- src/tests/test_utils/gl_raii.h | 17 +- util/EGLWindow.cpp | 22 +- util/EGLWindow.h | 17 +- util/shader_utils.cpp | 130 +- util/shader_utils.h | 23 +- 112 files changed, 4345 insertions(+), 4813 deletions(-) diff --git a/samples/hello_triangle/HelloTriangle.cpp b/samples/hello_triangle/HelloTriangle.cpp index 1c45417ba..8e949b4bb 100644 --- a/samples/hello_triangle/HelloTriangle.cpp +++ b/samples/hello_triangle/HelloTriangle.cpp @@ -14,33 +14,31 @@ // http://www.opengles-book.com #include "SampleApplication.h" -#include "shader_utils.h" + +#include "util/shader_utils.h" class HelloTriangleSample : public SampleApplication { public: HelloTriangleSample(int argc, char **argv) : SampleApplication("HelloTriangle", argc, argv, 2, 0) + {} + + bool initialize() override { - } + constexpr char kVS[] = R"(attribute vec4 vPosition; +void main() +{ + gl_Position = vPosition; +})"; - virtual bool initialize() - { - const std::string vs = - R"(attribute vec4 vPosition; - void main() - { - gl_Position = vPosition; - })"; + constexpr char kFS[] = R"(precision mediump float; +void main() +{ + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); +})"; - const std::string fs = - R"(precision mediump float; - void main() - { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - })"; - - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -51,18 +49,12 @@ class HelloTriangleSample : public SampleApplication return true; } - virtual void destroy() - { - glDeleteProgram(mProgram); - } + void destroy() override { glDeleteProgram(mProgram); } - virtual void draw() + void draw() override { - GLfloat vertices[] = - { - 0.0f, 0.5f, 0.0f, - -0.5f, -0.5f, 0.0f, - 0.5f, -0.5f, 0.0f, + GLfloat vertices[] = { + 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, }; // Set the viewport diff --git a/samples/mip_map_2d/MipMap2D.cpp b/samples/mip_map_2d/MipMap2D.cpp index 1810a2ddd..f541dd79e 100644 --- a/samples/mip_map_2d/MipMap2D.cpp +++ b/samples/mip_map_2d/MipMap2D.cpp @@ -14,38 +14,37 @@ // http://www.opengles-book.com #include "SampleApplication.h" -#include "shader_utils.h" + #include "texture_utils.h" +#include "util/shader_utils.h" class MipMap2DSample : public SampleApplication { public: MipMap2DSample(int argc, char **argv) : SampleApplication("MipMap2D", argc, argv) {} - virtual bool initialize() + bool initialize() override { - const std::string vs = - R"(uniform float u_offset; - attribute vec4 a_position; - attribute vec2 a_texCoord; - varying vec2 v_texCoord; - void main() - { - gl_Position = a_position; - gl_Position.x += u_offset; - v_texCoord = a_texCoord; - })"; + constexpr char kVS[] = R"(uniform float u_offset; +attribute vec4 a_position; +attribute vec2 a_texCoord; +varying vec2 v_texCoord; +void main() +{ + gl_Position = a_position; + gl_Position.x += u_offset; + v_texCoord = a_texCoord; +})"; - const std::string fs = - R"(precision mediump float; - varying vec2 v_texCoord; - uniform sampler2D s_texture; - void main() - { - gl_FragColor = texture2D(s_texture, v_texCoord); - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 v_texCoord; +uniform sampler2D s_texture; +void main() +{ + gl_FragColor = texture2D(s_texture, v_texCoord); +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -72,26 +71,25 @@ class MipMap2DSample : public SampleApplication return true; } - virtual void destroy() + void destroy() override { glDeleteProgram(mProgram); glDeleteTextures(1, &mTextureID); } - virtual void draw() + void draw() override { - const GLfloat vertices[] = - { - -0.25f, 0.5f, 0.0f, 5.0f, // Position 0 - 0.0f, 0.0f, // TexCoord 0 - -0.25f, -0.5f, 0.0f, 1.0f, // Position 1 - 0.0f, 1.0f, // TexCoord 1 - 0.25f, -0.5f, 0.0f, 1.0f, // Position 2 - 1.0f, 1.0f, // TexCoord 2 - 0.25f, 0.5f, 0.0f, 5.0f, // Position 3 - 1.0f, 0.0f // TexCoord 3 + const GLfloat vertices[] = { + -0.25f, 0.5f, 0.0f, 5.0f, // Position 0 + 0.0f, 0.0f, // TexCoord 0 + -0.25f, -0.5f, 0.0f, 1.0f, // Position 1 + 0.0f, 1.0f, // TexCoord 1 + 0.25f, -0.5f, 0.0f, 1.0f, // Position 2 + 1.0f, 1.0f, // TexCoord 2 + 0.25f, 0.5f, 0.0f, 5.0f, // Position 3 + 1.0f, 0.0f // TexCoord 3 }; - const GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + const GLushort indices[] = {0, 1, 2, 0, 2, 3}; // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); @@ -103,9 +101,10 @@ class MipMap2DSample : public SampleApplication glUseProgram(mProgram); // Load the vertex position - glVertexAttribPointer(mPositionLoc, 4, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), vertices); + glVertexAttribPointer(mPositionLoc, 4, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), vertices); // Load the texture coordinate - glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), vertices + 4); + glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), + vertices + 4); glEnableVertexAttribArray(mPositionLoc); glEnableVertexAttribArray(mTexCoordLoc); @@ -120,7 +119,7 @@ class MipMap2DSample : public SampleApplication // Draw quad with nearest sampling glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glUniform1f(mOffsetLoc, -0.6f); - glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); // Draw quad with trilinear filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); diff --git a/samples/multi_texture/MultiTexture.cpp b/samples/multi_texture/MultiTexture.cpp index 31c13a368..ffadfaed4 100644 --- a/samples/multi_texture/MultiTexture.cpp +++ b/samples/multi_texture/MultiTexture.cpp @@ -15,9 +15,9 @@ #include "SampleApplication.h" -#include "shader_utils.h" -#include "system_utils.h" #include "tga_utils.h" +#include "util/shader_utils.h" +#include "util/system_utils.h" class MultiTextureSample : public SampleApplication { @@ -35,34 +35,32 @@ class MultiTextureSample : public SampleApplication return LoadTextureFromTGAImage(img); } - virtual bool initialize() + bool initialize() override { - const std::string vs = - R"(attribute vec4 a_position; - attribute vec2 a_texCoord; - varying vec2 v_texCoord; - void main() - { - gl_Position = a_position; - v_texCoord = a_texCoord; - })"; + constexpr char kVS[] = R"(attribute vec4 a_position; +attribute vec2 a_texCoord; +varying vec2 v_texCoord; +void main() +{ + gl_Position = a_position; + v_texCoord = a_texCoord; +})"; - const std::string fs = - R"(precision mediump float; - varying vec2 v_texCoord; - uniform sampler2D s_baseMap; - uniform sampler2D s_lightMap; - void main() - { - vec4 baseColor; - vec4 lightColor; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 v_texCoord; +uniform sampler2D s_baseMap; +uniform sampler2D s_lightMap; +void main() +{ + vec4 baseColor; + vec4 lightColor; - baseColor = texture2D(s_baseMap, v_texCoord); - lightColor = texture2D(s_lightMap, v_texCoord); - gl_FragColor = baseColor * (lightColor + 0.25); - })"; + baseColor = texture2D(s_baseMap, v_texCoord); + lightColor = texture2D(s_lightMap, v_texCoord); + gl_FragColor = baseColor * (lightColor + 0.25); +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -73,7 +71,7 @@ class MultiTextureSample : public SampleApplication mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord"); // Get the sampler location - mBaseMapLoc = glGetUniformLocation(mProgram, "s_baseMap"); + mBaseMapLoc = glGetUniformLocation(mProgram, "s_baseMap"); mLightMapLoc = glGetUniformLocation(mProgram, "s_lightMap"); // Load the textures @@ -93,27 +91,26 @@ class MultiTextureSample : public SampleApplication return true; } - virtual void destroy() + void destroy() override { glDeleteProgram(mProgram); glDeleteTextures(1, &mBaseMapTexID); glDeleteTextures(1, &mLightMapTexID); } - virtual void draw() + void draw() override { - GLfloat vertices[] = - { - -0.5f, 0.5f, 0.0f, // Position 0 - 0.0f, 0.0f, // TexCoord 0 + GLfloat vertices[] = { + -0.5f, 0.5f, 0.0f, // Position 0 + 0.0f, 0.0f, // TexCoord 0 -0.5f, -0.5f, 0.0f, // Position 1 - 0.0f, 1.0f, // TexCoord 1 - 0.5f, -0.5f, 0.0f, // Position 2 - 1.0f, 1.0f, // TexCoord 2 - 0.5f, 0.5f, 0.0f, // Position 3 - 1.0f, 0.0f // TexCoord 3 + 0.0f, 1.0f, // TexCoord 1 + 0.5f, -0.5f, 0.0f, // Position 2 + 1.0f, 1.0f, // TexCoord 2 + 0.5f, 0.5f, 0.0f, // Position 3 + 1.0f, 0.0f // TexCoord 3 }; - GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + GLushort indices[] = {0, 1, 2, 0, 2, 3}; // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); @@ -127,7 +124,8 @@ class MultiTextureSample : public SampleApplication // Load the vertex position glVertexAttribPointer(mPositionLoc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), vertices); // Load the texture coordinate - glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), vertices + 3); + glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), + vertices + 3); glEnableVertexAttribArray(mPositionLoc); glEnableVertexAttribArray(mTexCoordLoc); diff --git a/samples/multi_window/MultiWindow.cpp b/samples/multi_window/MultiWindow.cpp index c0046a690..879b45dff 100644 --- a/samples/multi_window/MultiWindow.cpp +++ b/samples/multi_window/MultiWindow.cpp @@ -6,13 +6,13 @@ #include "SampleApplication.h" -#include #include +#include #include -#include "Matrix.h" -#include "random_utils.h" -#include "shader_utils.h" +#include "util/Matrix.h" +#include "util/random_utils.h" +#include "util/shader_utils.h" using namespace angle; @@ -21,26 +21,23 @@ class MultiWindowSample : public SampleApplication public: MultiWindowSample(int argc, char **argv) : SampleApplication("MultiWindow", argc, argv, 2, 0, 256, 256) - { - } + {} bool initialize() override { - const std::string vs = - R"(attribute vec4 vPosition; - void main() - { - gl_Position = vPosition; - })"; + constexpr char kVS[] = R"(attribute vec4 vPosition; +void main() +{ + gl_Position = vPosition; +})"; - const std::string fs = - R"(precision mediump float; - void main() - { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - })"; + constexpr char kFS[] = R"(precision mediump float; +void main() +{ + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -53,7 +50,7 @@ class MultiWindowSample : public SampleApplication window rootWindow; rootWindow.osWindow = getWindow(); - rootWindow.surface = getSurface(); + rootWindow.surface = getSurface(); mWindows.push_back(rootWindow); const size_t numWindows = 5; @@ -67,7 +64,8 @@ class MultiWindowSample : public SampleApplication return false; } - window.surface = eglCreateWindowSurface(getDisplay(), getConfig(), window.osWindow->getNativeWindow(), nullptr); + window.surface = eglCreateWindowSurface(getDisplay(), getConfig(), + window.osWindow->getNativeWindow(), nullptr); if (window.surface == EGL_NO_SURFACE) { return false; @@ -107,19 +105,19 @@ class MultiWindowSample : public SampleApplication void draw() override { - OSWindow* rootWindow = mWindows[0].osWindow; - int left = rootWindow->getX(); - int right = rootWindow->getX() + rootWindow->getWidth(); - int top = rootWindow->getY(); - int bottom = rootWindow->getY() + rootWindow->getHeight(); + OSWindow *rootWindow = mWindows[0].osWindow; + int left = rootWindow->getX(); + int right = rootWindow->getX() + rootWindow->getWidth(); + int top = rootWindow->getY(); + int bottom = rootWindow->getY() + rootWindow->getHeight(); for (auto &windowRecord : mWindows) { OSWindow *window = windowRecord.osWindow; - left = std::min(left, window->getX()); - right = std::max(right, window->getX() + window->getWidth()); - top = std::min(top, window->getY()); - bottom = std::max(bottom, window->getY() + window->getHeight()); + left = std::min(left, window->getX()); + right = std::max(right, window->getX() + window->getWidth()); + top = std::min(top, window->getY()); + bottom = std::max(bottom, window->getY() + window->getHeight()); } float midX = (left + right) * 0.5f; @@ -137,16 +135,19 @@ class MultiWindowSample : public SampleApplication eglMakeCurrent(getDisplay(), surface, surface, getContext()); - Matrix4 orthoMatrix = Matrix4::ortho(static_cast(window->getX()), static_cast(window->getX() + window->getWidth()), - static_cast(window->getY() + window->getHeight()), static_cast(window->getY()), - 0.0f, 1.0f); + Matrix4 orthoMatrix = + Matrix4::ortho(static_cast(window->getX()), + static_cast(window->getX() + window->getWidth()), + static_cast(window->getY() + window->getHeight()), + static_cast(window->getY()), 0.0f, 1.0f); Matrix4 mvpMatrix = orthoMatrix * viewMatrix * modelMatrix; - Vector3 vertices[] = - { + Vector3 vertices[] = { Matrix4::transform(mvpMatrix, Vector4(midX, static_cast(top), 0.0f, 1.0f)), - Matrix4::transform(mvpMatrix, Vector4(static_cast(left), static_cast(bottom), 0.0f, 1.0f)), - Matrix4::transform(mvpMatrix, Vector4(static_cast(right), static_cast(bottom), 0.0f, 1.0f)), + Matrix4::transform(mvpMatrix, Vector4(static_cast(left), + static_cast(bottom), 0.0f, 1.0f)), + Matrix4::transform(mvpMatrix, Vector4(static_cast(right), + static_cast(bottom), 0.0f, 1.0f)), }; // Set the viewport @@ -183,7 +184,7 @@ class MultiWindowSample : public SampleApplication // Window and surface data struct window { - OSWindow* osWindow; + OSWindow *osWindow; EGLSurface surface; }; std::vector mWindows; diff --git a/samples/multiple_draw_buffers/MultipleDrawBuffers.cpp b/samples/multiple_draw_buffers/MultipleDrawBuffers.cpp index 5948e08c5..84571b2e5 100644 --- a/samples/multiple_draw_buffers/MultipleDrawBuffers.cpp +++ b/samples/multiple_draw_buffers/MultipleDrawBuffers.cpp @@ -14,9 +14,10 @@ // http://www.opengles-book.com #include "SampleApplication.h" -#include "shader_utils.h" -#include "system_utils.h" + #include "texture_utils.h" +#include "util/shader_utils.h" +#include "util/system_utils.h" #include #include @@ -26,13 +27,12 @@ class MultipleDrawBuffersSample : public SampleApplication public: MultipleDrawBuffersSample(int argc, char **argv) : SampleApplication("MultipleDrawBuffers", argc, argv) - { - } + {} virtual bool initialize() { // Check EXT_draw_buffers is supported - char *extensionString = (char*)glGetString(GL_EXTENSIONS); + char *extensionString = (char *)glGetString(GL_EXTENSIONS); if (strstr(extensionString, "GL_EXT_draw_buffers") != nullptr) { // Retrieve the address of glDrawBuffersEXT from EGL @@ -118,25 +118,20 @@ class MultipleDrawBuffersSample : public SampleApplication virtual void draw() { - GLfloat vertices[] = - { - -0.8f, 0.8f, 0.0f, // Position 0 - 0.0f, 0.0f, // TexCoord 0 + GLfloat vertices[] = { + -0.8f, 0.8f, 0.0f, // Position 0 + 0.0f, 0.0f, // TexCoord 0 -0.8f, -0.8f, 0.0f, // Position 1 - 0.0f, 1.0f, // TexCoord 1 - 0.8f, -0.8f, 0.0f, // Position 2 - 1.0f, 1.0f, // TexCoord 2 - 0.8f, 0.8f, 0.0f, // Position 3 - 1.0f, 0.0f // TexCoord 3 - }; - GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; - GLenum drawBuffers[mFramebufferAttachmentCount] = - { - GL_COLOR_ATTACHMENT0_EXT, - GL_COLOR_ATTACHMENT1_EXT, - GL_COLOR_ATTACHMENT2_EXT, - GL_COLOR_ATTACHMENT3_EXT + 0.0f, 1.0f, // TexCoord 1 + 0.8f, -0.8f, 0.0f, // Position 2 + 1.0f, 1.0f, // TexCoord 2 + 0.8f, 0.8f, 0.0f, // Position 3 + 1.0f, 0.0f // TexCoord 3 }; + GLushort indices[] = {0, 1, 2, 0, 2, 3}; + GLenum drawBuffers[mFramebufferAttachmentCount] = { + GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, + GL_COLOR_ATTACHMENT3_EXT}; // Enable drawing to the four color attachments of the user framebuffer glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer); @@ -158,7 +153,8 @@ class MultipleDrawBuffersSample : public SampleApplication glEnableVertexAttribArray(mPositionLoc); // Load the texture coordinate - glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), vertices + 3); + glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), + vertices + 3); glEnableVertexAttribArray(mTexCoordLoc); // Bind the texture diff --git a/samples/multiview/Multiview.cpp b/samples/multiview/Multiview.cpp index da58ed015..975e984b0 100644 --- a/samples/multiview/Multiview.cpp +++ b/samples/multiview/Multiview.cpp @@ -6,8 +6,9 @@ // This sample shows basic usage of the GL_ANGLE_multiview extension. #include "SampleApplication.h" + #include "geometry_utils.h" -#include "shader_utils.h" +#include "util/shader_utils.h" #include @@ -59,10 +60,9 @@ class MultiviewSample : public SampleApplication mCubeNormalVBO(0), mCubeIBO(0), mCombineProgram(0) - { - } + {} - virtual bool initialize() + bool initialize() override { // Check whether the GL_ANGLE_multiview extension is supported. If not, abort // initialization. @@ -111,7 +111,7 @@ class MultiviewSample : public SampleApplication // The program has two code paths based on the gl_ViewID_OVR attribute which tells us which // view is currently being rendered to. Based on it we decide which eye's camera matrix to // use. - const std::string multiviewVS = + constexpr char kMultiviewVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -134,7 +134,7 @@ class MultiviewSample : public SampleApplication " gl_Position = uPerspective * p;\n" "}\n"; - const std::string multiviewFS = + constexpr char kMultiviewFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -146,7 +146,7 @@ class MultiviewSample : public SampleApplication " color = vec4(col, 1.);\n" "}\n"; - mMultiviewProgram = CompileProgram(multiviewVS, multiviewFS); + mMultiviewProgram = CompileProgram(kMultiviewVS, kMultiviewFS); if (!mMultiviewProgram) { return false; @@ -159,7 +159,7 @@ class MultiviewSample : public SampleApplication mMultiviewTranslationUniformLoc = glGetUniformLocation(mMultiviewProgram, "uTranslation"); // Create a normal program to combine both layers of the color array texture. - const std::string combineVS = + constexpr char kCombineVS[] = "#version 300 es\n" "in vec2 vIn;\n" "out vec2 uv;\n" @@ -169,7 +169,7 @@ class MultiviewSample : public SampleApplication " uv = vIn * .5 + vec2(.5);\n" "}\n"; - const std::string combineFS = + constexpr char kCombineFS[] = "#version 300 es\n" "precision mediump float;\n" "precision mediump sampler2DArray;\n" @@ -185,7 +185,7 @@ class MultiviewSample : public SampleApplication " color = vec4(texColor, 1.);\n" "}\n"; - mCombineProgram = CompileProgram(combineVS, combineFS); + mCombineProgram = CompileProgram(kCombineVS, kCombineFS); if (!mCombineProgram) { return false; @@ -235,7 +235,7 @@ class MultiviewSample : public SampleApplication return true; } - virtual void destroy() + void destroy() override { glDeleteProgram(mMultiviewProgram); glDeleteFramebuffers(1, &mMultiviewFBO); @@ -251,7 +251,7 @@ class MultiviewSample : public SampleApplication glDeleteProgram(mCombineProgram); } - virtual void draw() + void draw() override { // Draw to multiview fbo. { diff --git a/samples/particle_system/ParticleSystem.cpp b/samples/particle_system/ParticleSystem.cpp index 506f42771..934bc8d69 100644 --- a/samples/particle_system/ParticleSystem.cpp +++ b/samples/particle_system/ParticleSystem.cpp @@ -16,10 +16,10 @@ #include "SampleApplication.h" #include "common/vector_utils.h" -#include "shader_utils.h" -#include "random_utils.h" -#include "system_utils.h" #include "tga_utils.h" +#include "util/random_utils.h" +#include "util/shader_utils.h" +#include "util/system_utils.h" #define _USE_MATH_DEFINES #include @@ -33,59 +33,57 @@ class ParticleSystemSample : public SampleApplication bool initialize() override { - const std::string vs = - R"(uniform float u_time; - uniform vec3 u_centerPosition; - attribute float a_lifetime; - attribute vec3 a_startPosition; - attribute vec3 a_endPosition; - varying float v_lifetime; - void main() - { - if (u_time <= a_lifetime) - { - gl_Position.xyz = a_startPosition + (u_time * a_endPosition); - gl_Position.xyz += u_centerPosition; - gl_Position.w = 1.0; - } - else - { - gl_Position = vec4(-1000, -1000, 0, 0); - } - v_lifetime = 1.0 - (u_time / a_lifetime); - v_lifetime = clamp(v_lifetime, 0.0, 1.0); - gl_PointSize = (v_lifetime * v_lifetime) * 40.0; - })"; + constexpr char kVS[] = R"(uniform float u_time; +uniform vec3 u_centerPosition; +attribute float a_lifetime; +attribute vec3 a_startPosition; +attribute vec3 a_endPosition; +varying float v_lifetime; +void main() +{ + if (u_time <= a_lifetime) + { + gl_Position.xyz = a_startPosition + (u_time * a_endPosition); + gl_Position.xyz += u_centerPosition; + gl_Position.w = 1.0; + } + else + { + gl_Position = vec4(-1000, -1000, 0, 0); + } + v_lifetime = 1.0 - (u_time / a_lifetime); + v_lifetime = clamp(v_lifetime, 0.0, 1.0); + gl_PointSize = (v_lifetime * v_lifetime) * 40.0; +})"; - const std::string fs = - R"(precision mediump float; - uniform vec4 u_color; - varying float v_lifetime; - uniform sampler2D s_texture; - void main() - { - vec4 texColor; - texColor = texture2D(s_texture, gl_PointCoord); - gl_FragColor = vec4(u_color) * texColor; - gl_FragColor.a *= v_lifetime; - })"; + constexpr char kFS[] = R"(precision mediump float; +uniform vec4 u_color; +varying float v_lifetime; +uniform sampler2D s_texture; +void main() +{ + vec4 texColor; + texColor = texture2D(s_texture, gl_PointCoord); + gl_FragColor = vec4(u_color) * texColor; + gl_FragColor.a *= v_lifetime; +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; } // Get the attribute locations - mLifetimeLoc = glGetAttribLocation(mProgram, "a_lifetime"); + mLifetimeLoc = glGetAttribLocation(mProgram, "a_lifetime"); mStartPositionLoc = glGetAttribLocation(mProgram, "a_startPosition"); - mEndPositionLoc = glGetAttribLocation(mProgram, "a_endPosition"); + mEndPositionLoc = glGetAttribLocation(mProgram, "a_endPosition"); // Get the uniform locations - mTimeLoc = glGetUniformLocation(mProgram, "u_time"); + mTimeLoc = glGetUniformLocation(mProgram, "u_time"); mCenterPositionLoc = glGetUniformLocation(mProgram, "u_centerPosition"); - mColorLoc = glGetUniformLocation(mProgram, "u_color"); - mSamplerLoc = glGetUniformLocation(mProgram, "s_texture"); + mColorLoc = glGetUniformLocation(mProgram, "u_color"); + mSamplerLoc = glGetUniformLocation(mProgram, "s_texture"); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); @@ -166,9 +164,12 @@ class ParticleSystemSample : public SampleApplication glUseProgram(mProgram); // Load the vertex attributes - glVertexAttribPointer(mLifetimeLoc, 1, GL_FLOAT, GL_FALSE, sizeof(Particle), &mParticles[0].lifetime); - glVertexAttribPointer(mEndPositionLoc, 3, GL_FLOAT, GL_FALSE, sizeof(Particle), &mParticles[0].endPosition); - glVertexAttribPointer(mStartPositionLoc, 3, GL_FLOAT, GL_FALSE, sizeof(Particle), &mParticles[0].startPosition); + glVertexAttribPointer(mLifetimeLoc, 1, GL_FLOAT, GL_FALSE, sizeof(Particle), + &mParticles[0].lifetime); + glVertexAttribPointer(mEndPositionLoc, 3, GL_FLOAT, GL_FALSE, sizeof(Particle), + &mParticles[0].endPosition); + glVertexAttribPointer(mStartPositionLoc, 3, GL_FLOAT, GL_FALSE, sizeof(Particle), + &mParticles[0].startPosition); glEnableVertexAttribArray(mLifetimeLoc); glEnableVertexAttribArray(mEndPositionLoc); diff --git a/samples/post_sub_buffer/PostSubBuffer.cpp b/samples/post_sub_buffer/PostSubBuffer.cpp index f50a7ca85..7dcd839f7 100644 --- a/samples/post_sub_buffer/PostSubBuffer.cpp +++ b/samples/post_sub_buffer/PostSubBuffer.cpp @@ -13,11 +13,11 @@ // URLs: http://safari.informit.com/9780321563835 // http://www.opengles-book.com +#include "Matrix.h" #include "SampleApplication.h" +#include "geometry_utils.h" #include "shader_utils.h" #include "texture_utils.h" -#include "geometry_utils.h" -#include "Matrix.h" #include #include @@ -27,7 +27,7 @@ class PostSubBufferSample : public SampleApplication public: PostSubBufferSample(int argc, char **argv) : SampleApplication("PostSubBuffer", argc, argv) {} - virtual bool initialize() + bool initialize() override { mPostSubBufferNV = (PFNEGLPOSTSUBBUFFERNVPROC)eglGetProcAddress("eglPostSubBufferNV"); if (!mPostSubBufferNV) @@ -36,26 +36,24 @@ class PostSubBufferSample : public SampleApplication return false; } - const std::string vs = - R"(uniform mat4 u_mvpMatrix; - attribute vec4 a_position; - attribute vec2 a_texcoord; - varying vec2 v_texcoord; - void main() - { - gl_Position = u_mvpMatrix * a_position; - v_texcoord = a_texcoord; - })"; + constexpr char kVS[] = R"(uniform mat4 u_mvpMatrix; +attribute vec4 a_position; +attribute vec2 a_texcoord; +varying vec2 v_texcoord; +void main() +{ + gl_Position = u_mvpMatrix * a_position; + v_texcoord = a_texcoord; +})"; - const std::string fs = - R"(precision mediump float; - varying vec2 v_texcoord; - void main() - { - gl_FragColor = vec4(v_texcoord.x, v_texcoord.y, 1.0, 1.0); - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 v_texcoord; +void main() +{ + gl_FragColor = vec4(v_texcoord.x, v_texcoord.y, 1.0, 1.0); +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -86,17 +84,14 @@ class PostSubBufferSample : public SampleApplication return true; } - virtual void destroy() - { - glDeleteProgram(mProgram); - } + void destroy() override { glDeleteProgram(mProgram); } - virtual void step(float dt, double totalTime) + void step(float dt, double totalTime) override { mRotation = fmod(mRotation + (dt * 40.0f), 360.0f); - Matrix4 perspectiveMatrix = Matrix4::perspective(60.0f, float(getWindow()->getWidth()) / getWindow()->getHeight(), - 1.0f, 20.0f); + Matrix4 perspectiveMatrix = Matrix4::perspective( + 60.0f, float(getWindow()->getWidth()) / getWindow()->getHeight(), 1.0f, 20.0f); Matrix4 modelMatrix = Matrix4::translate(angle::Vector3(0.0f, 0.0f, -2.0f)) * Matrix4::rotate(mRotation, angle::Vector3(1.0f, 0.0f, 1.0f)); @@ -109,7 +104,7 @@ class PostSubBufferSample : public SampleApplication glUniformMatrix4fv(mMVPMatrixLoc, 1, GL_FALSE, mvpMatrix.data); } - virtual void draw() + void draw() override { // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); @@ -133,13 +128,14 @@ class PostSubBufferSample : public SampleApplication mCube.indices.data()); } - virtual void swap() + void swap() override { - // Instead of letting the application call eglSwapBuffers, call eglPostSubBufferNV here instead + // Instead of letting the application call eglSwapBuffers, call eglPostSubBufferNV here + // instead EGLint windowWidth = static_cast(getWindow()->getWidth()); EGLint windowHeight = static_cast(getWindow()->getHeight()); - EGLDisplay display = getDisplay(); - EGLSurface surface = getSurface(); + EGLDisplay display = getDisplay(); + EGLSurface surface = getSurface(); mPostSubBufferNV(display, surface, 60, 60, windowWidth - 120, windowHeight - 120); } diff --git a/samples/sample_util/SampleApplication.cpp b/samples/sample_util/SampleApplication.cpp index 1ef476b94..f1dc637f1 100644 --- a/samples/sample_util/SampleApplication.cpp +++ b/samples/sample_util/SampleApplication.cpp @@ -5,10 +5,10 @@ // #include "SampleApplication.h" -#include "EGLWindow.h" -#include "random_utils.h" #include "angle_gl.h" +#include "util/EGLWindow.h" +#include "util/random_utils.h" #include #include @@ -73,26 +73,18 @@ SampleApplication::SampleApplication(std::string name, mEGLWindow->setSwapInterval(0); } -SampleApplication::~SampleApplication() -{ -} +SampleApplication::~SampleApplication() {} bool SampleApplication::initialize() { return true; } -void SampleApplication::destroy() -{ -} +void SampleApplication::destroy() {} -void SampleApplication::step(float dt, double totalTime) -{ -} +void SampleApplication::step(float dt, double totalTime) {} -void SampleApplication::draw() -{ -} +void SampleApplication::draw() {} void SampleApplication::swap() { @@ -138,13 +130,13 @@ int SampleApplication::run() return -1; } - mRunning = true; + mRunning = true; int result = 0; if (!initialize()) { mRunning = false; - result = -1; + result = -1; } mTimer->start(); @@ -153,7 +145,7 @@ int SampleApplication::run() while (mRunning) { double elapsedTime = mTimer->getElapsedTime(); - double deltaTime = elapsedTime - prevTime; + double deltaTime = elapsedTime - prevTime; step(static_cast(deltaTime), elapsedTime); @@ -196,4 +188,4 @@ void SampleApplication::exit() bool SampleApplication::popEvent(Event *event) { return mOSWindow->popEvent(event); -} \ No newline at end of file +} diff --git a/samples/sample_util/SampleApplication.h b/samples/sample_util/SampleApplication.h index 1495ecd19..a459eeb0b 100644 --- a/samples/sample_util/SampleApplication.h +++ b/samples/sample_util/SampleApplication.h @@ -7,9 +7,9 @@ #ifndef SAMPLE_UTIL_SAMPLE_APPLICATION_H #define SAMPLE_UTIL_SAMPLE_APPLICATION_H +#include #include #include -#include #include #include @@ -62,4 +62,4 @@ class SampleApplication std::unique_ptr mOSWindow; }; -#endif // SAMPLE_UTIL_SAMPLE_APPLICATION_H +#endif // SAMPLE_UTIL_SAMPLE_APPLICATION_H diff --git a/samples/simple_instancing/SimpleInstancing.cpp b/samples/simple_instancing/SimpleInstancing.cpp index e34206da2..847acc6c6 100644 --- a/samples/simple_instancing/SimpleInstancing.cpp +++ b/samples/simple_instancing/SimpleInstancing.cpp @@ -16,8 +16,8 @@ #include "SampleApplication.h" #include "common/vector_utils.h" -#include "shader_utils.h" #include "texture_utils.h" +#include "util/shader_utils.h" #include #include @@ -30,55 +30,56 @@ class SimpleInstancingSample : public SampleApplication public: SimpleInstancingSample(int argc, char **argv) : SampleApplication("SimpleInstancing", argc, argv) - { - } + {} - virtual bool initialize() + bool initialize() override { // init instancing functions - char *extensionString = (char*)glGetString(GL_EXTENSIONS); + char *extensionString = (char *)glGetString(GL_EXTENSIONS); if (strstr(extensionString, "GL_ANGLE_instanced_arrays")) { - mVertexAttribDivisorANGLE = (PFNGLVERTEXATTRIBDIVISORANGLEPROC)eglGetProcAddress("glVertexAttribDivisorANGLE"); - mDrawArraysInstancedANGLE = (PFNGLDRAWARRAYSINSTANCEDANGLEPROC)eglGetProcAddress("glDrawArraysInstancedANGLE"); - mDrawElementsInstancedANGLE = (PFNGLDRAWELEMENTSINSTANCEDANGLEPROC)eglGetProcAddress("glDrawElementsInstancedANGLE"); + mVertexAttribDivisorANGLE = + (PFNGLVERTEXATTRIBDIVISORANGLEPROC)eglGetProcAddress("glVertexAttribDivisorANGLE"); + mDrawArraysInstancedANGLE = + (PFNGLDRAWARRAYSINSTANCEDANGLEPROC)eglGetProcAddress("glDrawArraysInstancedANGLE"); + mDrawElementsInstancedANGLE = (PFNGLDRAWELEMENTSINSTANCEDANGLEPROC)eglGetProcAddress( + "glDrawElementsInstancedANGLE"); } - if (!mVertexAttribDivisorANGLE || !mDrawArraysInstancedANGLE || !mDrawElementsInstancedANGLE) + if (!mVertexAttribDivisorANGLE || !mDrawArraysInstancedANGLE || + !mDrawElementsInstancedANGLE) { std::cerr << "Unable to load GL_ANGLE_instanced_arrays entry points."; return false; } - const std::string vs = - R"(attribute vec3 a_position; - attribute vec2 a_texCoord; - attribute vec3 a_instancePos; - varying vec2 v_texCoord; - void main() - { - gl_Position = vec4(a_position.xyz + a_instancePos.xyz, 1.0); - v_texCoord = a_texCoord; - })"; + constexpr char kVS[] = R"(attribute vec3 a_position; +attribute vec2 a_texCoord; +attribute vec3 a_instancePos; +varying vec2 v_texCoord; +void main() +{ + gl_Position = vec4(a_position.xyz + a_instancePos.xyz, 1.0); + v_texCoord = a_texCoord; +})"; - const std::string fs = - R"(precision mediump float; - varying vec2 v_texCoord; - uniform sampler2D s_texture; - void main() - { - gl_FragColor = texture2D(s_texture, v_texCoord); - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 v_texCoord; +uniform sampler2D s_texture; +void main() +{ + gl_FragColor = texture2D(s_texture, v_texCoord); +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; } // Get the attribute locations - mPositionLoc = glGetAttribLocation(mProgram, "a_position"); - mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord"); + mPositionLoc = glGetAttribLocation(mProgram, "a_position"); + mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord"); mInstancePosLoc = glGetAttribLocation(mProgram, "a_instancePos"); // Get the sampler location @@ -90,10 +91,10 @@ class SimpleInstancingSample : public SampleApplication // Initialize the vertex and index vectors const GLfloat quadRadius = 0.01f; - mVertices.push_back(Vector3(-quadRadius, quadRadius, 0.0f)); + mVertices.push_back(Vector3(-quadRadius, quadRadius, 0.0f)); mVertices.push_back(Vector3(-quadRadius, -quadRadius, 0.0f)); - mVertices.push_back(Vector3( quadRadius, -quadRadius, 0.0f)); - mVertices.push_back(Vector3( quadRadius, quadRadius, 0.0f)); + mVertices.push_back(Vector3(quadRadius, -quadRadius, 0.0f)); + mVertices.push_back(Vector3(quadRadius, quadRadius, 0.0f)); mTexcoords.push_back(Vector2(0.0f, 0.0f)); mTexcoords.push_back(Vector2(0.0f, 1.0f)); @@ -121,13 +122,13 @@ class SimpleInstancingSample : public SampleApplication return true; } - virtual void destroy() + void destroy() override { glDeleteProgram(mProgram); glDeleteTextures(1, &mTextureID); } - virtual void draw() + void draw() override { // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); diff --git a/samples/simple_texture_2d/SimpleTexture2D.cpp b/samples/simple_texture_2d/SimpleTexture2D.cpp index 9df0ad447..93da4a31f 100644 --- a/samples/simple_texture_2d/SimpleTexture2D.cpp +++ b/samples/simple_texture_2d/SimpleTexture2D.cpp @@ -14,38 +14,36 @@ // http://www.opengles-book.com #include "SampleApplication.h" -#include "shader_utils.h" + #include "texture_utils.h" +#include "util/shader_utils.h" class SimpleTexture2DSample : public SampleApplication { public: SimpleTexture2DSample(int argc, char **argv) : SampleApplication("SimpleTexture2D", argc, argv) + {} + + bool initialize() override { - } + constexpr char kVS[] = R"(attribute vec4 a_position; +attribute vec2 a_texCoord; +varying vec2 v_texCoord; +void main() +{ + gl_Position = a_position; + v_texCoord = a_texCoord; +})"; - virtual bool initialize() - { - const std::string vs = - R"(attribute vec4 a_position; - attribute vec2 a_texCoord; - varying vec2 v_texCoord; - void main() - { - gl_Position = a_position; - v_texCoord = a_texCoord; - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 v_texCoord; +uniform sampler2D s_texture; +void main() +{ + gl_FragColor = texture2D(s_texture, v_texCoord); +})"; - const std::string fs = - R"(precision mediump float; - varying vec2 v_texCoord; - uniform sampler2D s_texture; - void main() - { - gl_FragColor = texture2D(s_texture, v_texCoord); - })"; - - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -66,26 +64,25 @@ class SimpleTexture2DSample : public SampleApplication return true; } - virtual void destroy() + void destroy() override { glDeleteProgram(mProgram); glDeleteTextures(1, &mTexture); } - virtual void draw() + void draw() override { - GLfloat vertices[] = - { - -0.5f, 0.5f, 0.0f, // Position 0 - 0.0f, 0.0f, // TexCoord 0 + GLfloat vertices[] = { + -0.5f, 0.5f, 0.0f, // Position 0 + 0.0f, 0.0f, // TexCoord 0 -0.5f, -0.5f, 0.0f, // Position 1 - 0.0f, 1.0f, // TexCoord 1 - 0.5f, -0.5f, 0.0f, // Position 2 - 1.0f, 1.0f, // TexCoord 2 - 0.5f, 0.5f, 0.0f, // Position 3 - 1.0f, 0.0f // TexCoord 3 + 0.0f, 1.0f, // TexCoord 1 + 0.5f, -0.5f, 0.0f, // Position 2 + 1.0f, 1.0f, // TexCoord 2 + 0.5f, 0.5f, 0.0f, // Position 3 + 1.0f, 0.0f // TexCoord 3 }; - GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + GLushort indices[] = {0, 1, 2, 0, 2, 3}; // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); @@ -99,7 +96,8 @@ class SimpleTexture2DSample : public SampleApplication // Load the vertex position glVertexAttribPointer(mPositionLoc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), vertices); // Load the texture coordinate - glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), vertices + 3); + glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), + vertices + 3); glEnableVertexAttribArray(mPositionLoc); glEnableVertexAttribArray(mTexCoordLoc); diff --git a/samples/simple_texture_cubemap/SimpleTextureCubemap.cpp b/samples/simple_texture_cubemap/SimpleTextureCubemap.cpp index bf6b8b7db..c3f4437af 100644 --- a/samples/simple_texture_cubemap/SimpleTextureCubemap.cpp +++ b/samples/simple_texture_cubemap/SimpleTextureCubemap.cpp @@ -14,40 +14,38 @@ // http://www.opengles-book.com #include "SampleApplication.h" -#include "shader_utils.h" + #include "texture_utils.h" -#include "geometry_utils.h" +#include "util/geometry_utils.h" +#include "util/shader_utils.h" class SimpleTextureCubemapSample : public SampleApplication { public: SimpleTextureCubemapSample(int argc, char **argv) : SampleApplication("SimpleTextureCubemap", argc, argv) + {} + + bool initialize() override { - } + constexpr char kVS[] = R"(attribute vec4 a_position; +attribute vec3 a_normal; +varying vec3 v_normal; +void main() +{ + gl_Position = a_position; + v_normal = a_normal; +})"; - virtual bool initialize() - { - const std::string vs = - R"(attribute vec4 a_position; - attribute vec3 a_normal; - varying vec3 v_normal; - void main() - { - gl_Position = a_position; - v_normal = a_normal; - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec3 v_normal; +uniform samplerCube s_texture; +void main() +{ + gl_FragColor = textureCube(s_texture, v_normal); +})"; - const std::string fs = - R"(precision mediump float; - varying vec3 v_normal; - uniform samplerCube s_texture; - void main() - { - gl_FragColor = textureCube(s_texture, v_normal); - })"; - - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -55,7 +53,7 @@ class SimpleTextureCubemapSample : public SampleApplication // Get the attribute locations mPositionLoc = glGetAttribLocation(mProgram, "a_position"); - mNormalLoc = glGetAttribLocation(mProgram, "a_normal"); + mNormalLoc = glGetAttribLocation(mProgram, "a_normal"); // Get the sampler locations mSamplerLoc = glGetUniformLocation(mProgram, "s_texture"); @@ -73,13 +71,13 @@ class SimpleTextureCubemapSample : public SampleApplication return true; } - virtual void destroy() + void destroy() override { glDeleteProgram(mProgram); glDeleteTextures(1, &mTexture); } - virtual void draw() + void draw() override { // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); diff --git a/samples/simple_vertex_shader/SimpleVertexShader.cpp b/samples/simple_vertex_shader/SimpleVertexShader.cpp index da8552f46..8ef35d3b1 100644 --- a/samples/simple_vertex_shader/SimpleVertexShader.cpp +++ b/samples/simple_vertex_shader/SimpleVertexShader.cpp @@ -15,10 +15,10 @@ #include "SampleApplication.h" -#include "shader_utils.h" #include "texture_utils.h" -#include "geometry_utils.h" -#include "Matrix.h" +#include "util/Matrix.h" +#include "util/geometry_utils.h" +#include "util/shader_utils.h" #include @@ -27,31 +27,28 @@ class SimpleVertexShaderSample : public SampleApplication public: SimpleVertexShaderSample(int argc, char **argv) : SampleApplication("SimpleVertexShader", argc, argv) + {} + + bool initialize() override { - } + constexpr char kVS[] = R"(uniform mat4 u_mvpMatrix; +attribute vec4 a_position; +attribute vec2 a_texcoord; +varying vec2 v_texcoord; +void main() +{ + gl_Position = u_mvpMatrix * a_position; + v_texcoord = a_texcoord; +})"; - virtual bool initialize() - { - const std::string vs = - R"(uniform mat4 u_mvpMatrix; - attribute vec4 a_position; - attribute vec2 a_texcoord; - varying vec2 v_texcoord; - void main() - { - gl_Position = u_mvpMatrix * a_position; - v_texcoord = a_texcoord; - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 v_texcoord; +void main() +{ + gl_FragColor = vec4(v_texcoord.x, v_texcoord.y, 1.0, 1.0); +})"; - const std::string fs = - R"(precision mediump float; - varying vec2 v_texcoord; - void main() - { - gl_FragColor = vec4(v_texcoord.x, v_texcoord.y, 1.0, 1.0); - })"; - - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -77,17 +74,14 @@ class SimpleVertexShaderSample : public SampleApplication return true; } - virtual void destroy() - { - glDeleteProgram(mProgram); - } + void destroy() override { glDeleteProgram(mProgram); } - virtual void step(float dt, double totalTime) + void step(float dt, double totalTime) override { mRotation = fmod(mRotation + (dt * 40.0f), 360.0f); - Matrix4 perspectiveMatrix = Matrix4::perspective(60.0f, float(getWindow()->getWidth()) / getWindow()->getHeight(), - 1.0f, 20.0f); + Matrix4 perspectiveMatrix = Matrix4::perspective( + 60.0f, float(getWindow()->getWidth()) / getWindow()->getHeight(), 1.0f, 20.0f); Matrix4 modelMatrix = Matrix4::translate(angle::Vector3(0.0f, 0.0f, -2.0f)) * Matrix4::rotate(mRotation, angle::Vector3(1.0f, 0.0f, 1.0f)); @@ -100,7 +94,7 @@ class SimpleVertexShaderSample : public SampleApplication glUniformMatrix4fv(mMVPMatrixLoc, 1, GL_FALSE, mvpMatrix.data); } - virtual void draw() + void draw() override { // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); diff --git a/samples/stencil_operations/StencilOperations.cpp b/samples/stencil_operations/StencilOperations.cpp index 2e1575bd5..0099a0ac1 100644 --- a/samples/stencil_operations/StencilOperations.cpp +++ b/samples/stencil_operations/StencilOperations.cpp @@ -14,34 +14,32 @@ // http://www.opengles-book.com #include "SampleApplication.h" -#include "shader_utils.h" + +#include "util/shader_utils.h" class StencilOperationsSample : public SampleApplication { public: StencilOperationsSample(int argc, char **argv) : SampleApplication("StencilOperations", argc, argv) + {} + + bool initialize() override { - } + constexpr char kVS[] = R"(attribute vec4 a_position; +void main() +{ + gl_Position = a_position; +})"; - virtual bool initialize() - { - const std::string vs = - R"(attribute vec4 a_position; - void main() - { - gl_Position = a_position; - })"; + constexpr char kFS[] = R"(precision mediump float; +uniform vec4 u_color; +void main() +{ + gl_FragColor = u_color; +})"; - const std::string fs = - R"(precision mediump float; - uniform vec4 u_color; - void main() - { - gl_FragColor = u_color; - })"; - - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -69,61 +67,44 @@ class StencilOperationsSample : public SampleApplication return true; } - virtual void destroy() - { - glDeleteProgram(mProgram); - } + void destroy() override { glDeleteProgram(mProgram); } - virtual void draw() + void draw() override { - GLfloat vertices[] = - { - -0.75f, 0.25f, 0.50f, // Quad #0 - -0.25f, 0.25f, 0.50f, - -0.25f, 0.75f, 0.50f, - -0.75f, 0.75f, 0.50f, - 0.25f, 0.25f, 0.90f, // Quad #1 - 0.75f, 0.25f, 0.90f, - 0.75f, 0.75f, 0.90f, - 0.25f, 0.75f, 0.90f, - -0.75f, -0.75f, 0.50f, // Quad #2 - -0.25f, -0.75f, 0.50f, - -0.25f, -0.25f, 0.50f, - -0.75f, -0.25f, 0.50f, - 0.25f, -0.75f, 0.50f, // Quad #3 - 0.75f, -0.75f, 0.50f, - 0.75f, -0.25f, 0.50f, - 0.25f, -0.25f, 0.50f, - -1.00f, -1.00f, 0.00f, // Big Quad - 1.00f, -1.00f, 0.00f, - 1.00f, 1.00f, 0.00f, - -1.00f, 1.00f, 0.00f, + GLfloat vertices[] = { + -0.75f, 0.25f, 0.50f, // Quad #0 + -0.25f, 0.25f, 0.50f, -0.25f, 0.75f, 0.50f, -0.75f, 0.75f, 0.50f, + 0.25f, 0.25f, 0.90f, // Quad #1 + 0.75f, 0.25f, 0.90f, 0.75f, 0.75f, 0.90f, 0.25f, 0.75f, 0.90f, + -0.75f, -0.75f, 0.50f, // Quad #2 + -0.25f, -0.75f, 0.50f, -0.25f, -0.25f, 0.50f, -0.75f, -0.25f, 0.50f, + 0.25f, -0.75f, 0.50f, // Quad #3 + 0.75f, -0.75f, 0.50f, 0.75f, -0.25f, 0.50f, 0.25f, -0.25f, 0.50f, + -1.00f, -1.00f, 0.00f, // Big Quad + 1.00f, -1.00f, 0.00f, 1.00f, 1.00f, 0.00f, -1.00f, 1.00f, 0.00f, }; - GLubyte indices[][6] = - { - { 0, 1, 2, 0, 2, 3 }, // Quad #0 - { 4, 5, 6, 4, 6, 7 }, // Quad #1 - { 8, 9, 10, 8, 10, 11 }, // Quad #2 - { 12, 13, 14, 12, 14, 15 }, // Quad #3 - { 16, 17, 18, 16, 18, 19 }, // Big Quad + GLubyte indices[][6] = { + {0, 1, 2, 0, 2, 3}, // Quad #0 + {4, 5, 6, 4, 6, 7}, // Quad #1 + {8, 9, 10, 8, 10, 11}, // Quad #2 + {12, 13, 14, 12, 14, 15}, // Quad #3 + {16, 17, 18, 16, 18, 19}, // Big Quad }; static const size_t testCount = 4; - GLfloat colors[testCount][4] = - { - { 1.0f, 0.0f, 0.0f, 1.0f }, - { 0.0f, 1.0f, 0.0f, 1.0f }, - { 0.0f, 0.0f, 1.0f, 1.0f }, - { 1.0f, 1.0f, 0.0f, 0.0f }, + GLfloat colors[testCount][4] = { + {1.0f, 0.0f, 0.0f, 1.0f}, + {0.0f, 1.0f, 0.0f, 1.0f}, + {0.0f, 0.0f, 1.0f, 1.0f}, + {1.0f, 1.0f, 0.0f, 0.0f}, }; - GLuint stencilValues[testCount] = - { - 0x7, // Result of test 0 - 0x0, // Result of test 1 - 0x2, // Result of test 2 - 0xff // Result of test 3. We need to fill this value in at run-time + GLuint stencilValues[testCount] = { + 0x7, // Result of test 0 + 0x0, // Result of test 1 + 0x2, // Result of test 2 + 0xff // Result of test 3. We need to fill this value in at run-time }; // Set the viewport diff --git a/samples/tex_redef_microbench/TexRedefMicroBench.cpp b/samples/tex_redef_microbench/TexRedefMicroBench.cpp index bda9a7559..52299a727 100644 --- a/samples/tex_redef_microbench/TexRedefMicroBench.cpp +++ b/samples/tex_redef_microbench/TexRedefMicroBench.cpp @@ -14,8 +14,9 @@ // http://www.opengles-book.com #include "SampleApplication.h" -#include "shader_utils.h" + #include "texture_utils.h" +#include "util/shader_utils.h" #include #include @@ -52,14 +53,17 @@ class TexRedefBenchSample : public SampleApplication mPixelsNewTex(nullptr), mTimeFrame(false), mFrameCount(0) - { - } + {} - void defineSquareTexture2D(GLuint texId, GLsizei baseDimension, GLenum format, GLenum type, void* data) + void defineSquareTexture2D(GLuint texId, + GLsizei baseDimension, + GLenum format, + GLenum type, + void *data) { glBindTexture(GL_TEXTURE_2D, texId); GLsizei curDim = baseDimension; - GLuint level = 0; + GLuint level = 0; while (curDim >= 1) { @@ -71,12 +75,12 @@ class TexRedefBenchSample : public SampleApplication void createPixelData() { - mPixelsResize = new GLubyte[512 * 512 * 4]; - mPixelsNewTex = new GLubyte[512 * 512 * 4]; - GLubyte *pixPtr0 = mPixelsResize; - GLubyte *pixPtr1 = mPixelsNewTex; - GLubyte zeroPix[] = { 0, 192, 192, 255 }; - GLubyte onePix[] = { 192, 0, 0, 255 }; + mPixelsResize = new GLubyte[512 * 512 * 4]; + mPixelsNewTex = new GLubyte[512 * 512 * 4]; + GLubyte *pixPtr0 = mPixelsResize; + GLubyte *pixPtr1 = mPixelsNewTex; + GLubyte zeroPix[] = {0, 192, 192, 255}; + GLubyte onePix[] = {192, 0, 0, 255}; for (int i = 0; i < 512 * 512; ++i) { memcpy(pixPtr0, zeroPix, 4 * sizeof(GLubyte)); @@ -86,28 +90,26 @@ class TexRedefBenchSample : public SampleApplication } } - virtual bool initialize() + bool initialize() override { - const std::string vs = - R"(attribute vec4 a_position; - attribute vec2 a_texCoord; - varying vec2 v_texCoord; - void main() - { - gl_Position = a_position; - v_texCoord = a_texCoord; - })"; + constexpr char kVS[] = R"(attribute vec4 a_position; +attribute vec2 a_texCoord; +varying vec2 v_texCoord; +void main() +{ + gl_Position = a_position; + v_texCoord = a_texCoord; +})"; - const std::string fs = - R"(precision mediump float; - varying vec2 v_texCoord; - uniform sampler2D s_texture; - void main() - { - gl_FragColor = texture2D(s_texture, v_texCoord); - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 v_texCoord; +uniform sampler2D s_texture; +void main() +{ + gl_FragColor = texture2D(s_texture, v_texCoord); +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -128,37 +130,36 @@ class TexRedefBenchSample : public SampleApplication glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - mOrigTimer = CreateTimer(); - mResizeDrawTimer = CreateTimer(); + mOrigTimer = CreateTimer(); + mResizeDrawTimer = CreateTimer(); mResizeDefineTimer = CreateTimer(); - mNewTexDrawTimer = CreateTimer(); + mNewTexDrawTimer = CreateTimer(); mNewTexDefineTimer = CreateTimer(); return true; } - virtual void destroy() + void destroy() override { glDeleteProgram(mProgram); - delete [] mPixelsResize; - delete [] mPixelsNewTex; + delete[] mPixelsResize; + delete[] mPixelsNewTex; } - virtual void draw() + void draw() override { - GLfloat vertices[] = - { - -0.5f, 0.5f, 0.0f, // Position 0 - 0.0f, 0.0f, // TexCoord 0 + GLfloat vertices[] = { + -0.5f, 0.5f, 0.0f, // Position 0 + 0.0f, 0.0f, // TexCoord 0 -0.5f, -0.5f, 0.0f, // Position 1 - 0.0f, 1.0f, // TexCoord 1 - 0.5f, -0.5f, 0.0f, // Position 2 - 1.0f, 1.0f, // TexCoord 2 - 0.5f, 0.5f, 0.0f, // Position 3 - 1.0f, 0.0f // TexCoord 3 + 0.0f, 1.0f, // TexCoord 1 + 0.5f, -0.5f, 0.0f, // Position 2 + 1.0f, 1.0f, // TexCoord 2 + 0.5f, 0.5f, 0.0f, // Position 3 + 1.0f, 0.0f // TexCoord 3 }; - GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + GLushort indices[] = {0, 1, 2, 0, 2, 3}; // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); @@ -172,7 +173,8 @@ class TexRedefBenchSample : public SampleApplication // Load the vertex position glVertexAttribPointer(mPositionLoc, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), vertices); // Load the texture coordinate - glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), vertices + 3); + glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), + vertices + 3); glEnableVertexAttribArray(mPositionLoc); glEnableVertexAttribArray(mTexCoordLoc); @@ -193,13 +195,14 @@ class TexRedefBenchSample : public SampleApplication } glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); - + if (mTimeFrame) - { + { mOrigTimer->stop(); - // This timer indicates draw time for an already-created texture resident on the GPU, which - // needs no updates. It will be faster than the other draws. - std::cout << "Original texture draw: " << mOrigTimer->getElapsedTime() * 1000 << "msec" << std::endl; + // This timer indicates draw time for an already-created texture resident on the GPU, + // which needs no updates. It will be faster than the other draws. + std::cout << "Original texture draw: " << mOrigTimer->getElapsedTime() * 1000 << "msec" + << std::endl; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -211,11 +214,13 @@ class TexRedefBenchSample : public SampleApplication mResizeDrawTimer->start(); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); mResizeDrawTimer->stop(); - // This timer indicates draw time for a texture which has already been used in a draw, causing the - // underlying resource to be allocated, and then resized, requiring resource reallocation and - // related overhead. - std::cout << "Resized texture definition: " << mResizeDefineTimer->getElapsedTime() * 1000 << "msec" << std::endl; - std::cout << "Resized texture draw: " << mResizeDrawTimer->getElapsedTime() * 1000 << "msec" << std::endl; + // This timer indicates draw time for a texture which has already been used in a draw, + // causing the underlying resource to be allocated, and then resized, requiring resource + // reallocation and related overhead. + std::cout << "Resized texture definition: " + << mResizeDefineTimer->getElapsedTime() * 1000 << "msec" << std::endl; + std::cout << "Resized texture draw: " << mResizeDrawTimer->getElapsedTime() * 1000 + << "msec" << std::endl; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -227,11 +232,14 @@ class TexRedefBenchSample : public SampleApplication mNewTexDrawTimer->start(); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); mNewTexDrawTimer->stop(); - // This timer indicates draw time for a texture newly created this frame. The underlying resource - // will need to be created, but because it has not previously been used, there is no already-resident - // texture object to manage. This draw is expected to be faster than the resized texture draw. - std::cout << "Newly created texture definition: " << mNewTexDefineTimer->getElapsedTime() * 1000 << "msec" << std::endl; - std::cout << "Newly created texture draw: " << mNewTexDrawTimer->getElapsedTime() * 1000 << "msec" << std::endl; + // This timer indicates draw time for a texture newly created this frame. The underlying + // resource will need to be created, but because it has not previously been used, there + // is no already-resident texture object to manage. This draw is expected to be faster + // than the resized texture draw. + std::cout << "Newly created texture definition: " + << mNewTexDefineTimer->getElapsedTime() * 1000 << "msec" << std::endl; + std::cout << "Newly created texture draw: " << mNewTexDrawTimer->getElapsedTime() * 1000 + << "msec" << std::endl; } if (mFrameCount == 5) @@ -254,8 +262,8 @@ class TexRedefBenchSample : public SampleApplication GLint mSamplerLoc; // Texture handle - GLuint mTextureIds[2]; // 0: texture created, then resized - // 1: texture newly created with TexImage + GLuint mTextureIds[2]; // 0: texture created, then resized + // 1: texture newly created with TexImage // Texture pixel data GLubyte *mPixelsResize; diff --git a/samples/texture_wrap/TextureWrap.cpp b/samples/texture_wrap/TextureWrap.cpp index 8608ac436..a8f812b92 100644 --- a/samples/texture_wrap/TextureWrap.cpp +++ b/samples/texture_wrap/TextureWrap.cpp @@ -14,38 +14,37 @@ // http://www.opengles-book.com #include "SampleApplication.h" -#include "shader_utils.h" + #include "texture_utils.h" +#include "util/shader_utils.h" class TextureWrapSample : public SampleApplication { public: TextureWrapSample(int argc, char **argv) : SampleApplication("TextureWrap", argc, argv) {} - virtual bool initialize() + bool initialize() override { - const std::string vs = - R"(uniform float u_offset; - attribute vec4 a_position; - attribute vec2 a_texCoord; - varying vec2 v_texCoord; - void main() - { - gl_Position = a_position; - gl_Position.x += u_offset; - v_texCoord = a_texCoord; - })"; + constexpr char kVS[] = R"(uniform float u_offset; +attribute vec4 a_position; +attribute vec2 a_texCoord; +varying vec2 v_texCoord; +void main() +{ + gl_Position = a_position; + gl_Position.x += u_offset; + v_texCoord = a_texCoord; +})"; - const std::string fs = - R"(precision mediump float; - varying vec2 v_texCoord; - uniform sampler2D s_texture; - void main() - { - gl_FragColor = texture2D(s_texture, v_texCoord); - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 v_texCoord; +uniform sampler2D s_texture; +void main() +{ + gl_FragColor = texture2D(s_texture, v_texCoord); +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -69,25 +68,21 @@ class TextureWrapSample : public SampleApplication return true; } - virtual void destroy() - { - glDeleteProgram(mProgram); - } + void destroy() override { glDeleteProgram(mProgram); } - virtual void draw() + void draw() override { - GLfloat vertices[] = - { - -0.3f, 0.3f, 0.0f, 1.0f, // Position 0 - -1.0f, -1.0f, // TexCoord 0 - -0.3f, -0.3f, 0.0f, 1.0f, // Position 1 - -1.0f, 2.0f, // TexCoord 1 - 0.3f, -0.3f, 0.0f, 1.0f, // Position 2 - 2.0f, 2.0f, // TexCoord 2 - 0.3f, 0.3f, 0.0f, 1.0f, // Position 3 - 2.0f, -1.0f // TexCoord 3 + GLfloat vertices[] = { + -0.3f, 0.3f, 0.0f, 1.0f, // Position 0 + -1.0f, -1.0f, // TexCoord 0 + -0.3f, -0.3f, 0.0f, 1.0f, // Position 1 + -1.0f, 2.0f, // TexCoord 1 + 0.3f, -0.3f, 0.0f, 1.0f, // Position 2 + 2.0f, 2.0f, // TexCoord 2 + 0.3f, 0.3f, 0.0f, 1.0f, // Position 3 + 2.0f, -1.0f // TexCoord 3 }; - GLushort indices[] = { 0, 1, 2, 0, 2, 3 }; + GLushort indices[] = {0, 1, 2, 0, 2, 3}; // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); @@ -103,7 +98,8 @@ class TextureWrapSample : public SampleApplication glEnableVertexAttribArray(mPositionLoc); // Load the texture coordinate - glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), vertices + 4); + glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), + vertices + 4); glEnableVertexAttribArray(mTexCoordLoc); // Set the sampler texture unit to 0 @@ -128,22 +124,22 @@ class TextureWrapSample : public SampleApplication glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices); } -private: + private: // Handle to a program object - GLuint mProgram; + GLuint mProgram; - // Attribute locations - GLint mPositionLoc; - GLint mTexCoordLoc; + // Attribute locations + GLint mPositionLoc; + GLint mTexCoordLoc; - // Sampler location - GLint mSamplerLoc; + // Sampler location + GLint mSamplerLoc; - // Offset location - GLint mOffsetLoc; + // Offset location + GLint mOffsetLoc; - // Texture handle - GLuint mTexture; + // Texture handle + GLuint mTexture; }; int main(int argc, char **argv) diff --git a/samples/tri_fan_microbench/TriFanMicroBench.cpp b/samples/tri_fan_microbench/TriFanMicroBench.cpp index 2c3b42f6a..d3874c151 100644 --- a/samples/tri_fan_microbench/TriFanMicroBench.cpp +++ b/samples/tri_fan_microbench/TriFanMicroBench.cpp @@ -14,12 +14,13 @@ // http://www.opengles-book.com #include "SampleApplication.h" -#include "shader_utils.h" + +#include "util/shader_utils.h" #include #include -// This small sample compares the per-frame render time for a series of +// This small sample compares the per-frame render time for a series of // squares drawn with TRIANGLE_FANS versus squares drawn with TRIANGLES. // To exacerbate differences between the two, we use a large collection // of short buffers with pre-translated vertex data. @@ -29,35 +30,34 @@ class TriangleFanBenchSample : public SampleApplication public: TriangleFanBenchSample(int argc, char **argv) : SampleApplication("Microbench", argc, argv, 2, 0, 1280, 1280), mFrameCount(0) - { - } + {} void createVertexBuffers() { - const unsigned int slices = 8; + const unsigned int slices = 8; const unsigned int numFanVertices = slices + 2; - const unsigned int fanFloats = numFanVertices * 3; + const unsigned int fanFloats = numFanVertices * 3; mNumFanVerts = numFanVertices; const GLfloat halfDim = 0.0625; - GLfloat fanVertices[] = - { 0.0f, 0.0f, 0.0f, // center - -halfDim, -halfDim, 0.0f, // LL - -halfDim, 0.0f, 0.0f, // CL - -halfDim, halfDim, 0.0f, // UL - 0.0f, halfDim, 0.0f, // UC - halfDim, halfDim, 0.0f, // UR - halfDim, 0.0f, 0.0f, // CR - halfDim, -halfDim, 0.0f, // LR - 0.0f, -halfDim, 0.0f, // LC - -halfDim, -halfDim, 0.0f // LL (closes the fan) - }; + GLfloat fanVertices[] = { + 0.0f, 0.0f, 0.0f, // center + -halfDim, -halfDim, 0.0f, // LL + -halfDim, 0.0f, 0.0f, // CL + -halfDim, halfDim, 0.0f, // UL + 0.0f, halfDim, 0.0f, // UC + halfDim, halfDim, 0.0f, // UR + halfDim, 0.0f, 0.0f, // CR + halfDim, -halfDim, 0.0f, // LR + 0.0f, -halfDim, 0.0f, // LC + -halfDim, -halfDim, 0.0f // LL (closes the fan) + }; - const GLfloat xMin = -1.0f; // We leave viewport/worldview untransformed in this sample + const GLfloat xMin = -1.0f; // We leave viewport/worldview untransformed in this sample const GLfloat xMax = 1.0f; const GLfloat yMin = -1.0f; - //const GLfloat yMax = 1.0f; + // const GLfloat yMax = 1.0f; glGenBuffers(mNumSquares, mFanBufId); @@ -65,10 +65,10 @@ class TriangleFanBenchSample : public SampleApplication GLfloat yOffset = yMin; for (unsigned int i = 0; i < mNumSquares; ++i) { - GLfloat tempVerts[fanFloats] = { 0 }; + GLfloat tempVerts[fanFloats] = {0}; for (unsigned int j = 0; j < numFanVertices; ++j) { - tempVerts[j * 3] = fanVertices[j * 3] + xOffset; + tempVerts[j * 3] = fanVertices[j * 3] + xOffset; tempVerts[j * 3 + 1] = fanVertices[j * 3 + 1] + yOffset; tempVerts[j * 3 + 2] = 0.0f; } @@ -85,7 +85,7 @@ class TriangleFanBenchSample : public SampleApplication } const unsigned int numTriVertices = slices * 3; - const unsigned int triFloats = numTriVertices * 3; + const unsigned int triFloats = numTriVertices * 3; GLfloat triVertices[triFloats]; GLfloat *triPointer = triVertices; @@ -93,17 +93,19 @@ class TriangleFanBenchSample : public SampleApplication for (unsigned int i = 0; i < slices; ++i) { - memcpy(triPointer, fanVertices, 3 * sizeof(GLfloat)); // copy center point as first vertex for this slice + memcpy(triPointer, fanVertices, + 3 * sizeof(GLfloat)); // copy center point as first vertex for this slice triPointer += 3; for (unsigned int j = 1; j < 3; ++j) { - GLfloat *vertex = &(fanVertices[(i + j) * 3]); // copy two outer vertices for this point + GLfloat *vertex = + &(fanVertices[(i + j) * 3]); // copy two outer vertices for this point memcpy(triPointer, vertex, 3 * sizeof(GLfloat)); triPointer += 3; } } - //GLfloat triVertices2[triFloats]; + // GLfloat triVertices2[triFloats]; glGenBuffers(mNumSquares, mTriBufId); xOffset = xMin; yOffset = yMin; @@ -114,7 +116,7 @@ class TriangleFanBenchSample : public SampleApplication GLfloat tempVerts[triFloats]; for (unsigned int j = 0; j < numTriVertices; ++j) { - tempVerts[j * 3] = triPointer[0] + xOffset; + tempVerts[j * 3] = triPointer[0] + xOffset; tempVerts[j * 3 + 1] = triPointer[1] + yOffset; tempVerts[j * 3 + 2] = 0.0f; triPointer += 3; @@ -131,23 +133,21 @@ class TriangleFanBenchSample : public SampleApplication } } - virtual bool initialize() + bool initialize() override { - const std::string vs = - R"(attribute vec4 vPosition; - void main() - { - gl_Position = vPosition; - })"; + constexpr char kVS[] = R"(attribute vec4 vPosition; +void main() +{ + gl_Position = vPosition; +})"; - const std::string fs = - R"(precision mediump float; - void main() - { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - })"; + constexpr char kFS[] = R"(precision mediump float; +void main() +{ + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); if (!mProgram) { return false; @@ -157,22 +157,26 @@ class TriangleFanBenchSample : public SampleApplication createVertexBuffers(); - mFanTimer = CreateTimer(); - mTriTimer = CreateTimer(); + mFanTimer = CreateTimer(); + mTriTimer = CreateTimer(); mFanTotalTime = 0; mTriTotalTime = 0; return true; } - virtual void destroy() + void destroy() override { - std::cout << "Total draw time using TRIANGLE_FAN: " << mFanTotalTime << "ms (" << (float)mFanTotalTime / (float)mFrameCount << " average per frame)" << std::endl; - std::cout << "Total draw time using TRIANGLES: " << mTriTotalTime << "ms (" << (float)mTriTotalTime / (float)mFrameCount << " average per frame)" << std::endl; + std::cout << "Total draw time using TRIANGLE_FAN: " << mFanTotalTime << "ms (" + << (float)mFanTotalTime / (float)mFrameCount << " average per frame)" + << std::endl; + std::cout << "Total draw time using TRIANGLES: " << mTriTotalTime << "ms (" + << (float)mTriTotalTime / (float)mFrameCount << " average per frame)" + << std::endl; glDeleteProgram(mProgram); } - virtual void draw() + void draw() override { // Set the viewport glViewport(0, 0, getWindow()->getWidth(), getWindow()->getHeight()); @@ -196,11 +200,12 @@ class TriangleFanBenchSample : public SampleApplication } mFanTimer->stop(); - mFanTotalTime += static_cast(mFanTimer->getElapsedTime() * 1000); // convert from usec to msec when accumulating + mFanTotalTime += static_cast( + mFanTimer->getElapsedTime() * 1000); // convert from usec to msec when accumulating // Clear to eliminate driver-side gains from occlusion glClear(GL_COLOR_BUFFER_BIT); - + // Draw using triangles, stored in VBO mTriTimer->start(); for (unsigned i = 1; i < mNumSquares; ++i) @@ -211,7 +216,8 @@ class TriangleFanBenchSample : public SampleApplication } mTriTimer->stop(); - mTriTotalTime += static_cast(mTriTimer->getElapsedTime() * 1000); // convert from usec to msec when accumulating + mTriTotalTime += static_cast( + mTriTimer->getElapsedTime() * 1000); // convert from usec to msec when accumulating mFrameCount++; } diff --git a/src/tests/BUILD.gn b/src/tests/BUILD.gn index e151cfca3..c32d5bff3 100644 --- a/src/tests/BUILD.gn +++ b/src/tests/BUILD.gn @@ -238,7 +238,10 @@ if (is_win || is_linux || is_android || is_mac) { import("angle_perftests.gni") test("angle_perftests") { - include_dirs = [ "../../src/tests" ] + include_dirs = [ + ".", + "../..", + ] sources = angle_perf_tests_sources diff --git a/src/tests/egl_tests/EGLIOSurfaceClientBufferTest.cpp b/src/tests/egl_tests/EGLIOSurfaceClientBufferTest.cpp index 27e331112..ce459fe56 100644 --- a/src/tests/egl_tests/EGLIOSurfaceClientBufferTest.cpp +++ b/src/tests/egl_tests/EGLIOSurfaceClientBufferTest.cpp @@ -211,14 +211,14 @@ class IOSurfaceClientBufferTest : public ANGLETest GLTexture texture; bindIOSurfaceToTexture(ioSurface, 1, 1, 0, internalFormat, type, &pbuffer, &texture); - const std::string vs = + constexpr char kVS[] = "attribute vec4 position;\n" "void main()\n" "{\n" " gl_Position = vec4(position.xy, 0.0, 1.0);\n" "}\n"; - const std::string fs = + constexpr char kFS[] = "#extension GL_ARB_texture_rectangle : require\n" "precision mediump float;\n" "uniform sampler2DRect tex;\n" @@ -227,7 +227,7 @@ class IOSurfaceClientBufferTest : public ANGLETest " gl_FragColor = texture2DRect(tex, vec2(0, 0));\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLint location = glGetUniformLocation(program, "tex"); diff --git a/src/tests/egl_tests/EGLPresentPathD3D11Test.cpp b/src/tests/egl_tests/EGLPresentPathD3D11Test.cpp index 0bfc7e302..b234d58d2 100644 --- a/src/tests/egl_tests/EGLPresentPathD3D11Test.cpp +++ b/src/tests/egl_tests/EGLPresentPathD3D11Test.cpp @@ -183,7 +183,7 @@ class EGLPresentPathD3D11 : public testing::TestWithParam GLuint m2DProgram; GLint mTexture2DUniformLocation; - const std::string vertexShaderSource = + constexpr char kVS[] = R"(precision highp float; attribute vec4 position; varying vec2 texcoord; @@ -194,7 +194,7 @@ class EGLPresentPathD3D11 : public testing::TestWithParam texcoord = (position.xy * 0.5) + 0.5; })"; - const std::string fragmentShaderSource2D = + constexpr char kFS[] = R"(precision highp float; uniform sampler2D tex; varying vec2 texcoord; @@ -204,7 +204,7 @@ class EGLPresentPathD3D11 : public testing::TestWithParam gl_FragColor = texture2D(tex, texcoord); })"; - m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D); + m2DProgram = CompileProgram(kVS, kFS); mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex"); uint8_t textureInitData[16] = { diff --git a/src/tests/egl_tests/EGLProgramCacheControlTest.cpp b/src/tests/egl_tests/EGLProgramCacheControlTest.cpp index b50a57a27..45f46fa1b 100644 --- a/src/tests/egl_tests/EGLProgramCacheControlTest.cpp +++ b/src/tests/egl_tests/EGLProgramCacheControlTest.cpp @@ -176,9 +176,8 @@ TEST_P(EGLProgramCacheControlTest, SaveAndReload) { ANGLE_SKIP_TEST_IF(!extensionAvailable() || !programBinaryAvailable()); - const std::string vertexShader = - "attribute vec4 position; void main() { gl_Position = position; }"; - const std::string fragmentShader = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }"; + constexpr char kVS[] = "attribute vec4 position; void main() { gl_Position = position; }"; + constexpr char kFS[] = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }"; // Link a program, which will miss the cache. { @@ -186,7 +185,7 @@ TEST_P(EGLProgramCacheControlTest, SaveAndReload) glClear(GL_COLOR_BUFFER_BIT); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "position", 0.5f); EXPECT_GL_NO_ERROR(); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); @@ -229,7 +228,7 @@ TEST_P(EGLProgramCacheControlTest, SaveAndReload) glClear(GL_COLOR_BUFFER_BIT); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "position", 0.5f); EXPECT_GL_NO_ERROR(); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); diff --git a/src/tests/egl_tests/EGLStreamTest.cpp b/src/tests/egl_tests/EGLStreamTest.cpp index 4de464c5c..cfa27a486 100644 --- a/src/tests/egl_tests/EGLStreamTest.cpp +++ b/src/tests/egl_tests/EGLStreamTest.cpp @@ -658,7 +658,8 @@ TEST_P(EGLStreamTest, StreamProducerTextureNV12End2End) getClientMajorVersion() >= 3 && extensionEnabled("GL_OES_EGL_image_external_essl3"); // yuv to rgb conversion shader using Microsoft's given conversion formulas - std::string yuvVS, yuvPS; + const char *yuvVS = nullptr; + const char *yuvPS = nullptr; if (useESSL3Shaders) { yuvVS = @@ -721,8 +722,7 @@ TEST_P(EGLStreamTest, StreamProducerTextureNV12End2End) "}\n"; } - GLuint program = CompileProgram(yuvVS, yuvPS); - ASSERT_NE(0u, program); + ANGLE_GL_PROGRAM(program, yuvVS, yuvPS); GLuint yUniform = glGetUniformLocation(program, "y"); GLuint uvUniform = glGetUniformLocation(program, "uv"); diff --git a/src/tests/egl_tests/EGLSurfaceTest.cpp b/src/tests/egl_tests/EGLSurfaceTest.cpp index 3f8be47da..9fc79a8e1 100644 --- a/src/tests/egl_tests/EGLSurfaceTest.cpp +++ b/src/tests/egl_tests/EGLSurfaceTest.cpp @@ -175,21 +175,7 @@ class EGLSurfaceTest : public testing::Test GLuint createProgram() { - const std::string testVertexShaderSource = - R"(attribute highp vec4 position; - - void main(void) - { - gl_Position = position; - })"; - - const std::string testFragmentShaderSource = - R"(void main(void) - { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - })"; - - return CompileProgram(testVertexShaderSource, testFragmentShaderSource); + return CompileProgram(angle::essl1_shaders::vs::Simple(), angle::essl1_shaders::fs::Red()); } void drawWithProgram(GLuint program) @@ -197,7 +183,8 @@ class EGLSurfaceTest : public testing::Test glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); - GLint positionLocation = glGetAttribLocation(program, "position"); + GLint positionLocation = + glGetAttribLocation(program, angle::essl1_shaders::PositionAttrib()); glUseProgram(program); @@ -676,7 +663,8 @@ TEST_F(EGLSurfaceTest, CreateSurfaceWithMSAA) glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); - GLint positionLocation = glGetAttribLocation(program, "position"); + GLint positionLocation = glGetAttribLocation(program, angle::essl1_shaders::PositionAttrib()); + ASSERT_NE(-1, positionLocation); glUseProgram(program); diff --git a/src/tests/gl_tests/AtomicCounterBufferTest.cpp b/src/tests/gl_tests/AtomicCounterBufferTest.cpp index 1fd91abb3..d751f1b80 100644 --- a/src/tests/gl_tests/AtomicCounterBufferTest.cpp +++ b/src/tests/gl_tests/AtomicCounterBufferTest.cpp @@ -51,20 +51,20 @@ class AtomicCounterBufferTest31 : public AtomicCounterBufferTest // Linking should fail if counters in vertex shader exceed gl_MaxVertexAtomicCounters. TEST_P(AtomicCounterBufferTest31, ExceedMaxVertexAtomicCounters) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "layout(binding = 0) uniform atomic_uint foo[gl_MaxVertexAtomicCounters + 1];\n" "void main()\n" "{\n" " atomicCounterIncrement(foo[0]);\n" "}\n"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "void main()\n" "{\n" "}\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } @@ -72,21 +72,21 @@ TEST_P(AtomicCounterBufferTest31, ExceedMaxVertexAtomicCounters) // GLSL ES Spec 3.10.4, section 9.2.1. TEST_P(AtomicCounterBufferTest31, OffsetNotAllSpecified) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "layout(binding = 0, offset = 4) uniform atomic_uint foo;\n" "void main()\n" "{\n" " atomicCounterIncrement(foo);\n" "}\n"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "layout(binding = 0) uniform atomic_uint foo;\n" "void main()\n" "{\n" "}\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } @@ -94,21 +94,21 @@ TEST_P(AtomicCounterBufferTest31, OffsetNotAllSpecified) // value. TEST_P(AtomicCounterBufferTest31, OffsetNotAllSpecifiedWithSameValue) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "layout(binding = 0, offset = 4) uniform atomic_uint foo;\n" "void main()\n" "{\n" " atomicCounterIncrement(foo);\n" "}\n"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "layout(binding = 0, offset = 8) uniform atomic_uint foo;\n" "void main()\n" "{\n" "}\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } @@ -145,7 +145,7 @@ TEST_P(AtomicCounterBufferTest31, AtomicCounterRead) // http://anglebug.com/1729 ANGLE_SKIP_TEST_IF(IsD3D11()); - const std::string &fragShader = + constexpr char kFS[] = "#version 310 es\n" "precision highp float;\n" "layout(binding = 0, offset = 4) uniform atomic_uint ac;\n" @@ -157,7 +157,7 @@ TEST_P(AtomicCounterBufferTest31, AtomicCounterRead) " if (a1 == 3u) my_color = vec4(1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), fragShader); + ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS); glUseProgram(program.get()); @@ -181,7 +181,7 @@ TEST_P(AtomicCounterBufferTest31, AtomicCounterIncrementAndDecrement) // http://anglebug.com/1729 ANGLE_SKIP_TEST_IF(IsD3D11()); - const std::string &csSource = + constexpr char kCS[] = "#version 310 es\n" "layout(local_size_x=1, local_size_y=1, local_size_z=1) in;\n" "layout(binding = 0, offset = 4) uniform atomic_uint ac[2];\n" @@ -191,7 +191,7 @@ TEST_P(AtomicCounterBufferTest31, AtomicCounterIncrementAndDecrement) " atomicCounterDecrement(ac[1]);\n" "}\n"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); diff --git a/src/tests/gl_tests/AttributeLayoutTest.cpp b/src/tests/gl_tests/AttributeLayoutTest.cpp index a8353d3ca..c21ae164d 100644 --- a/src/tests/gl_tests/AttributeLayoutTest.cpp +++ b/src/tests/gl_tests/AttributeLayoutTest.cpp @@ -251,7 +251,7 @@ class AttributeLayoutTest : public ANGLETest glDisable(GL_DEPTH_TEST); - const std::string vertexSource = + constexpr char kVS[] = "attribute mediump vec2 coord;\n" "attribute mediump vec3 color;\n" "varying mediump vec3 vcolor;\n" @@ -261,14 +261,14 @@ class AttributeLayoutTest : public ANGLETest " vcolor = color;\n" "}\n"; - const std::string fragmentSource = + constexpr char kFS[] = "varying mediump vec3 vcolor;\n" "void main(void)\n" "{\n" " gl_FragColor = vec4(vcolor, 0);\n" "}\n"; - mProgram = CompileProgram(vertexSource, fragmentSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); glUseProgram(mProgram); diff --git a/src/tests/gl_tests/BPTCCompressedTextureTest.cpp b/src/tests/gl_tests/BPTCCompressedTextureTest.cpp index 329a19a76..4578b4868 100644 --- a/src/tests/gl_tests/BPTCCompressedTextureTest.cpp +++ b/src/tests/gl_tests/BPTCCompressedTextureTest.cpp @@ -40,29 +40,27 @@ class BPTCCompressedTextureTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vsSource = - R"(precision highp float; - attribute vec4 position; - varying vec2 texcoord; + constexpr char kVS[] = R"(precision highp float; +attribute vec4 position; +varying vec2 texcoord; - void main() - { - gl_Position = position; - texcoord = (position.xy * 0.5) + 0.5; - texcoord.y = 1.0 - texcoord.y; - })"; +void main() +{ + gl_Position = position; + texcoord = (position.xy * 0.5) + 0.5; + texcoord.y = 1.0 - texcoord.y; +})"; - const std::string textureFSSource = - R"(precision highp float; - uniform sampler2D tex; - varying vec2 texcoord; + constexpr char kFS[] = R"(precision highp float; +uniform sampler2D tex; +varying vec2 texcoord; - void main() - { - gl_FragColor = texture2D(tex, texcoord); - })"; +void main() +{ + gl_FragColor = texture2D(tex, texcoord); +})"; - mTextureProgram = CompileProgram(vsSource, textureFSSource); + mTextureProgram = CompileProgram(kVS, kFS); if (mTextureProgram == 0) { FAIL() << "shader compilation failed."; diff --git a/src/tests/gl_tests/BindUniformLocationTest.cpp b/src/tests/gl_tests/BindUniformLocationTest.cpp index fb74b6645..d6fab5eb0 100644 --- a/src/tests/gl_tests/BindUniformLocationTest.cpp +++ b/src/tests/gl_tests/BindUniformLocationTest.cpp @@ -60,21 +60,20 @@ TEST_P(BindUniformLocationTest, Basic) ASSERT_NE(mBindUniformLocation, nullptr); - const std::string fsSource = - R"(precision mediump float; - uniform vec4 u_colorC; - uniform vec4 u_colorB[2]; - uniform vec4 u_colorA; - void main() - { - gl_FragColor = u_colorA + u_colorB[0] + u_colorB[1] + u_colorC; - })"; + constexpr char kFS[] = R"(precision mediump float; +uniform vec4 u_colorC; +uniform vec4 u_colorB[2]; +uniform vec4 u_colorA; +void main() +{ + gl_FragColor = u_colorA + u_colorB[0] + u_colorB[1] + u_colorC; +})"; GLint colorALocation = 3; GLint colorBLocation = 10; GLint colorCLocation = 5; - mProgram = CompileProgram(essl1_shaders::vs::Simple(), fsSource, [&](GLuint program) { + mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS, [&](GLuint program) { mBindUniformLocation(program, colorALocation, "u_colorA"); mBindUniformLocation(program, colorBLocation, "u_colorB[0]"); mBindUniformLocation(program, colorCLocation, "u_colorC"); @@ -104,21 +103,20 @@ TEST_P(BindUniformLocationTest, SamplerLocation) ASSERT_NE(mBindUniformLocation, nullptr); - const std::string fsSource = - R"(precision mediump float; - uniform vec4 u_colorA; - uniform vec4 u_colorB[2]; - uniform sampler2D u_sampler; - void main() - { - gl_FragColor = u_colorA + u_colorB[0] + u_colorB[1] + texture2D(u_sampler, vec2(0, 0)); - })"; + constexpr char kFS[] = R"(precision mediump float; +uniform vec4 u_colorA; +uniform vec4 u_colorB[2]; +uniform sampler2D u_sampler; +void main() +{ + gl_FragColor = u_colorA + u_colorB[0] + u_colorB[1] + texture2D(u_sampler, vec2(0, 0)); +})"; GLint colorALocation = 3; GLint colorBLocation = 10; GLint samplerLocation = 1; - mProgram = CompileProgram(essl1_shaders::vs::Simple(), fsSource, [&](GLuint program) { + mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS, [&](GLuint program) { mBindUniformLocation(program, colorALocation, "u_colorA"); mBindUniformLocation(program, colorBLocation, "u_colorB[0]"); mBindUniformLocation(program, samplerLocation, "u_sampler"); @@ -156,7 +154,7 @@ TEST_P(BindUniformLocationTest, ConflictsDetection) ASSERT_NE(nullptr, mBindUniformLocation); - const std::string fsSource = + constexpr char kFS[] = R"(precision mediump float; uniform vec4 u_colorA; uniform vec4 u_colorB; @@ -169,7 +167,7 @@ TEST_P(BindUniformLocationTest, ConflictsDetection) GLint colorBLocation = 4; GLuint vs = CompileShader(GL_VERTEX_SHADER, essl1_shaders::vs::Simple()); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); mProgram = glCreateProgram(); glAttachShader(mProgram, vs); @@ -200,7 +198,7 @@ TEST_P(BindUniformLocationTest, Compositor) ASSERT_NE(nullptr, mBindUniformLocation); - const std::string vsSource = + constexpr char kVS[] = R"(attribute vec4 a_position; attribute vec2 a_texCoord; uniform mat4 matrix; @@ -215,7 +213,7 @@ TEST_P(BindUniformLocationTest, Compositor) gl_Position = matrix * a_position; })"; - const std::string fsSource = + constexpr char kFS[] = R"(precision mediump float; varying vec4 v_color; uniform float alpha; @@ -245,7 +243,7 @@ TEST_P(BindUniformLocationTest, Compositor) int multiplierLocation = counter++; int colorCLocation = counter++; - mProgram = CompileProgram(vsSource, fsSource, [&](GLuint program) { + mProgram = CompileProgram(kVS, kFS, [&](GLuint program) { mBindUniformLocation(program, matrixLocation, "matrix"); mBindUniformLocation(program, colorALocation, "color_a"); mBindUniformLocation(program, colorBLocation, "color_b"); @@ -291,21 +289,20 @@ TEST_P(BindUniformLocationTest, UnusedUniformUpdate) ASSERT_NE(nullptr, mBindUniformLocation); - const std::string fsSource = - R"(precision mediump float; - uniform vec4 u_colorA; - uniform float u_colorU; - uniform vec4 u_colorC; - void main() - { - gl_FragColor = u_colorA + u_colorC; - })"; + constexpr char kFS[] = R"(precision mediump float; +uniform vec4 u_colorA; +uniform float u_colorU; +uniform vec4 u_colorC; +void main() +{ + gl_FragColor = u_colorA + u_colorC; +})"; const GLint colorULocation = 1; const GLint nonexistingLocation = 5; const GLint unboundLocation = 6; - mProgram = CompileProgram(essl1_shaders::vs::Simple(), fsSource, [&](GLuint program) { + mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS, [&](GLuint program) { mBindUniformLocation(program, colorULocation, "u_colorU"); // The non-existing uniform should behave like existing, but optimized away // uniform. @@ -376,7 +373,7 @@ TEST_P(BindUniformLocationTest, UseSamplerWhenUnusedUniforms) ASSERT_NE(nullptr, mBindUniformLocation); - const std::string fsSource = + constexpr char kFS[] = R"(uniform sampler2D tex; void main() { @@ -385,7 +382,7 @@ TEST_P(BindUniformLocationTest, UseSamplerWhenUnusedUniforms) const GLuint texLocation = 54; - mProgram = CompileProgram(essl1_shaders::vs::Simple(), fsSource, [&](GLuint program) { + mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS, [&](GLuint program) { mBindUniformLocation(program, texLocation, "tex"); }); ASSERT_NE(0u, mProgram); @@ -403,7 +400,7 @@ TEST_P(BindUniformLocationTest, SameLocationForUsedAndUnusedUniform) ASSERT_NE(nullptr, mBindUniformLocation); - const std::string fsSource = + constexpr char kFS[] = R"(precision mediump float; uniform vec4 a; uniform vec4 b; @@ -414,7 +411,7 @@ TEST_P(BindUniformLocationTest, SameLocationForUsedAndUnusedUniform) const GLuint location = 54; - mProgram = CompileProgram(essl1_shaders::vs::Zero(), fsSource, [&](GLuint program) { + mProgram = CompileProgram(essl1_shaders::vs::Zero(), kFS, [&](GLuint program) { mBindUniformLocation(program, location, "a"); mBindUniformLocation(program, location, "b"); }); @@ -430,8 +427,8 @@ class BindUniformLocationES31Test : public BindUniformLocationTest protected: BindUniformLocationES31Test() : BindUniformLocationTest() {} - void linkProgramWithUniformLocation(const std::string &vs, - const std::string &fs, + void linkProgramWithUniformLocation(const char *vs, + const char *fs, const char *uniformName, GLint uniformLocation) { @@ -447,7 +444,7 @@ TEST_P(BindUniformLocationES31Test, ConsistentWithLocationLayoutQualifier) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_CHROMIUM_bind_uniform_location")); - const std::string fsSource = + constexpr char kFS[] = "#version 310 es\n" "uniform layout(location=2) highp sampler2D tex;\n" "out highp vec4 my_FragColor;\n" @@ -458,7 +455,7 @@ TEST_P(BindUniformLocationES31Test, ConsistentWithLocationLayoutQualifier) const GLuint texLocation = 2; - linkProgramWithUniformLocation(essl31_shaders::vs::Zero(), fsSource, "tex", texLocation); + linkProgramWithUniformLocation(essl31_shaders::vs::Zero(), kFS, "tex", texLocation); GLint linked = GL_FALSE; glGetProgramiv(mProgram, GL_LINK_STATUS, &linked); @@ -477,7 +474,7 @@ TEST_P(BindUniformLocationES31Test, LocationLayoutQualifierOverridesAPIBinding) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_CHROMIUM_bind_uniform_location")); - const std::string fsSource = + constexpr char kFS[] = "#version 310 es\n" "uniform layout(location=2) highp sampler2D tex;\n" "out highp vec4 my_FragColor;\n" @@ -489,7 +486,7 @@ TEST_P(BindUniformLocationES31Test, LocationLayoutQualifierOverridesAPIBinding) const GLuint shaderTexLocation = 2; const GLuint texLocation = 3; - linkProgramWithUniformLocation(essl31_shaders::vs::Zero(), fsSource, "tex", texLocation); + linkProgramWithUniformLocation(essl31_shaders::vs::Zero(), kFS, "tex", texLocation); GLint linked = GL_FALSE; glGetProgramiv(mProgram, GL_LINK_STATUS, &linked); @@ -510,7 +507,7 @@ TEST_P(BindUniformLocationES31Test, LocationLayoutQualifierConflictsWithAPIBindi { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_CHROMIUM_bind_uniform_location")); - const std::string fsSource = + constexpr char kFS[] = "#version 310 es\n" "uniform layout(location=2) highp sampler2D tex;\n" "uniform highp sampler2D tex2;\n" @@ -522,7 +519,7 @@ TEST_P(BindUniformLocationES31Test, LocationLayoutQualifierConflictsWithAPIBindi const GLuint tex2Location = 2; - linkProgramWithUniformLocation(essl31_shaders::vs::Zero(), fsSource, "tex2", tex2Location); + linkProgramWithUniformLocation(essl31_shaders::vs::Zero(), kFS, "tex2", tex2Location); GLint linked = GL_FALSE; glGetProgramiv(mProgram, GL_LINK_STATUS, &linked); @@ -534,7 +531,7 @@ TEST_P(BindUniformLocationES31Test, ArrayOfArrays) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_CHROMIUM_bind_uniform_location")); - const std::string fsSource = + constexpr char kFS[] = R"(#version 310 es precision highp float; uniform vec4 sourceColor[2][1]; @@ -546,8 +543,7 @@ TEST_P(BindUniformLocationES31Test, ArrayOfArrays) const GLuint location = 8; - linkProgramWithUniformLocation(essl31_shaders::vs::Simple(), fsSource, "sourceColor[1]", - location); + linkProgramWithUniformLocation(essl31_shaders::vs::Simple(), kFS, "sourceColor[1]", location); GLint linked = GL_FALSE; glGetProgramiv(mProgram, GL_LINK_STATUS, &linked); diff --git a/src/tests/gl_tests/BlendFuncExtendedTest.cpp b/src/tests/gl_tests/BlendFuncExtendedTest.cpp index ba0d58955..90a2b1c1e 100644 --- a/src/tests/gl_tests/BlendFuncExtendedTest.cpp +++ b/src/tests/gl_tests/BlendFuncExtendedTest.cpp @@ -325,7 +325,7 @@ TEST_P(EXTBlendFuncExtendedDrawTestES3, FragmentOutputLocationAPI) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_blend_func_extended")); - const std::string &kFragColorShader = R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es #extension GL_EXT_blend_func_extended : require precision mediump float; uniform vec4 src0; @@ -337,7 +337,7 @@ void main() { outSrc1 = src1; })"; - mProgram = CompileProgram(essl3_shaders::vs::Simple(), kFragColorShader, [](GLuint program) { + mProgram = CompileProgram(essl3_shaders::vs::Simple(), kFS, [](GLuint program) { glBindFragDataLocationIndexedEXT(program, 0, 0, "outSrc0"); glBindFragDataLocationIndexedEXT(program, 0, 1, "outSrc1"); }); @@ -356,7 +356,7 @@ TEST_P(EXTBlendFuncExtendedDrawTestES3, FragmentOutputLocationsAPIAndAutomatic) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_blend_func_extended")); - const std::string &kFragColorShader = R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es #extension GL_EXT_blend_func_extended : require precision mediump float; uniform vec4 src0; @@ -368,7 +368,7 @@ void main() { outSrc1 = src1; })"; - mProgram = CompileProgram(essl3_shaders::vs::Simple(), kFragColorShader, [](GLuint program) { + mProgram = CompileProgram(essl3_shaders::vs::Simple(), kFS, [](GLuint program) { glBindFragDataLocationIndexedEXT(program, 0, 1, "outSrc1"); }); @@ -389,7 +389,7 @@ TEST_P(EXTBlendFuncExtendedDrawTestES3, FragmentArrayOutputLocationsAPI) // TODO: Investigate this mac-only failure. http://angleproject.com/1085 ANGLE_SKIP_TEST_IF(IsOSX()); - const std::string &kFragColorShader = R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es #extension GL_EXT_blend_func_extended : require precision mediump float; uniform vec4 src0; @@ -401,7 +401,7 @@ void main() { outSrc1[0] = src1; })"; - mProgram = CompileProgram(essl3_shaders::vs::Simple(), kFragColorShader, [](GLuint program) { + mProgram = CompileProgram(essl3_shaders::vs::Simple(), kFS, [](GLuint program) { // Specs aren't very clear on what kind of name should be used when binding location for // array variables. We only allow names that do include the "[0]" suffix. glBindFragDataLocationIndexedEXT(program, 0, 0, "outSrc0[0]"); @@ -430,7 +430,7 @@ TEST_P(EXTBlendFuncExtendedTestES3, FragmentOutputLocationConflict) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_blend_func_extended")); - const std::string &kFragShader = R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es #extension GL_EXT_blend_func_extended : require precision mediump float; uniform vec4 src0; @@ -443,7 +443,7 @@ void main() { })"; GLuint vs = CompileShader(GL_VERTEX_SHADER, essl3_shaders::vs::Simple()); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFragShader); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); ASSERT_NE(0u, vs); ASSERT_NE(0u, fs); @@ -471,7 +471,7 @@ TEST_P(EXTBlendFuncExtendedTestES3, FragmentOutputLocationForNonexistentOutput) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_blend_func_extended")); - const std::string &kFragShader = R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es #extension GL_EXT_blend_func_extended : require precision mediump float; uniform vec4 src0; @@ -481,7 +481,7 @@ void main() { })"; GLuint vs = CompileShader(GL_VERTEX_SHADER, essl3_shaders::vs::Simple()); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFragShader); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); ASSERT_NE(0u, vs); ASSERT_NE(0u, fs); @@ -514,7 +514,7 @@ TEST_P(EXTBlendFuncExtendedTestES3, FragmentOutputLocationsPartiallyAutomatic) glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); ANGLE_SKIP_TEST_IF(maxDrawBuffers < 4); - const std::string &kFragShader = R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es #extension GL_EXT_blend_func_extended : require precision mediump float; uniform vec4 src0; @@ -531,7 +531,7 @@ void main() { out3 = src3; })"; - GLuint program = CompileProgram(essl3_shaders::vs::Simple(), kFragShader); + GLuint program = CompileProgram(essl3_shaders::vs::Simple(), kFS); ASSERT_NE(0u, program); GLint location = glGetFragDataLocation(program, "out0"); @@ -566,7 +566,7 @@ void main() { })"; GLuint vs = CompileShader(GL_VERTEX_SHADER, essl3_shaders::vs::Simple()); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragShader.str()); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragShader.str().c_str()); ASSERT_NE(0u, vs); ASSERT_NE(0u, fs); diff --git a/src/tests/gl_tests/BlitFramebufferANGLETest.cpp b/src/tests/gl_tests/BlitFramebufferANGLETest.cpp index b4bf45d09..66c1bc1ba 100644 --- a/src/tests/gl_tests/BlitFramebufferANGLETest.cpp +++ b/src/tests/gl_tests/BlitFramebufferANGLETest.cpp @@ -1168,7 +1168,7 @@ TEST_P(BlitFramebufferTest, MultisampleDepth) glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get()); glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_DEPTH_COMPONENT24, 256, 256); - const std::string &fragment = + constexpr char kFS[] = "#version 300 es\n" "out mediump vec4 red;\n" "void main() {\n" @@ -1176,7 +1176,7 @@ TEST_P(BlitFramebufferTest, MultisampleDepth) " gl_FragDepth = 0.5;\n" "}"; - ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), fragment); + ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), kFS); GLFramebuffer framebuffer; glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); diff --git a/src/tests/gl_tests/BufferDataTest.cpp b/src/tests/gl_tests/BufferDataTest.cpp index 374834047..6515e9394 100644 --- a/src/tests/gl_tests/BufferDataTest.cpp +++ b/src/tests/gl_tests/BufferDataTest.cpp @@ -35,28 +35,26 @@ class BufferDataTest : public ANGLETest { ANGLETest::SetUp(); - const char *vsSource = - R"(attribute vec4 position; - attribute float in_attrib; - varying float v_attrib; - void main() - { - v_attrib = in_attrib; - gl_Position = position; - })"; + constexpr char kVS[] = R"(attribute vec4 position; +attribute float in_attrib; +varying float v_attrib; +void main() +{ + v_attrib = in_attrib; + gl_Position = position; +})"; - const char *fsSource = - R"(precision mediump float; - varying float v_attrib; - void main() - { - gl_FragColor = vec4(v_attrib, 0, 0, 1); - })"; + constexpr char kFS[] = R"(precision mediump float; +varying float v_attrib; +void main() +{ + gl_FragColor = vec4(v_attrib, 0, 0, 1); +})"; glGenBuffers(1, &mBuffer); ASSERT_NE(mBuffer, 0U); - mProgram = CompileProgram(vsSource, fsSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(mProgram, 0U); mAttribLocation = glGetAttribLocation(mProgram, "in_attrib"); @@ -239,23 +237,21 @@ class IndexedBufferCopyTest : public ANGLETest { ANGLETest::SetUp(); - const char *vsSource = - R"(attribute vec3 in_attrib; - varying vec3 v_attrib; - void main() - { - v_attrib = in_attrib; - gl_Position = vec4(0.0, 0.0, 0.5, 1.0); - gl_PointSize = 100.0; - })"; + constexpr char kVS[] = R"(attribute vec3 in_attrib; +varying vec3 v_attrib; +void main() +{ + v_attrib = in_attrib; + gl_Position = vec4(0.0, 0.0, 0.5, 1.0); + gl_PointSize = 100.0; +})"; - const char *fsSource = - R"(precision mediump float; - varying vec3 v_attrib; - void main() - { - gl_FragColor = vec4(v_attrib, 1); - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec3 v_attrib; +void main() +{ + gl_FragColor = vec4(v_attrib, 1); +})"; glGenBuffers(2, mBuffers); ASSERT_NE(mBuffers[0], 0U); @@ -264,7 +260,7 @@ class IndexedBufferCopyTest : public ANGLETest glGenBuffers(1, &mElementBuffer); ASSERT_NE(mElementBuffer, 0U); - mProgram = CompileProgram(vsSource, fsSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(mProgram, 0U); mAttribLocation = glGetAttribLocation(mProgram, "in_attrib"); @@ -531,13 +527,13 @@ TEST_P(BufferDataOverflowTest, VertexBufferIntegerOverflow) vertexShaderStr << "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "varying highp float v_attrib;\n" "void main() {\n" " gl_FragColor = vec4(v_attrib, 0, 0, 1);\n" "}"; - ANGLE_GL_PROGRAM(program, vertexShaderStr.str(), fragmentShader); + ANGLE_GL_PROGRAM(program, vertexShaderStr.str().c_str(), kFS); glUseProgram(program.get()); std::vector data(numItems, 1.0f); diff --git a/src/tests/gl_tests/BuiltinVariableTest.cpp b/src/tests/gl_tests/BuiltinVariableTest.cpp index 853c131a4..fb6845223 100644 --- a/src/tests/gl_tests/BuiltinVariableTest.cpp +++ b/src/tests/gl_tests/BuiltinVariableTest.cpp @@ -30,7 +30,7 @@ class BuiltinVariableVertexIdTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "precision highp float;\n" "in vec4 position;\n" @@ -43,7 +43,7 @@ class BuiltinVariableVertexIdTest : public ANGLETest " color = vec4(gl_VertexID != expectedID, gl_VertexID == expectedID, 0.0, 1.0);" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "in vec4 color;\n" @@ -53,7 +53,7 @@ class BuiltinVariableVertexIdTest : public ANGLETest " fragColor = color;\n" "}\n"; - mProgram = CompileProgram(vsSource, fsSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); mPositionLocation = glGetAttribLocation(mProgram, "position"); @@ -211,7 +211,7 @@ class BuiltinVariableFragDepthClampingFloatRBOTest : public ANGLETest // Writes a fixed detph value and green. // Section 15.2.3 of the GL 4.5 specification says that conversion is not // done but clamping is so the output depth should be in [0.0, 1.0] - const std::string depthFs = + constexpr char kFS[] = R"(#version 300 es precision highp float; layout(location = 0) out vec4 fragColor; @@ -221,7 +221,7 @@ class BuiltinVariableFragDepthClampingFloatRBOTest : public ANGLETest fragColor = vec4(0.0, 1.0, 0.0, 1.0); })"; - mProgram = CompileProgram(essl3_shaders::vs::Simple(), depthFs); + mProgram = CompileProgram(essl3_shaders::vs::Simple(), kFS); ASSERT_NE(0u, mProgram); mDepthLocation = glGetUniformLocation(mProgram, "u_depth"); diff --git a/src/tests/gl_tests/ClearTest.cpp b/src/tests/gl_tests/ClearTest.cpp index 5bf126ff2..b42b8abe7 100644 --- a/src/tests/gl_tests/ClearTest.cpp +++ b/src/tests/gl_tests/ClearTest.cpp @@ -501,7 +501,7 @@ TEST_P(ClearTestES3, MixedSRGBClear) // flush or finish after ClearBufferfv or each draw. TEST_P(ClearTestES3, RepeatedClear) { - const std::string &vertexSource = + constexpr char kVS[] = "#version 300 es\n" "in highp vec2 position;\n" "out highp vec2 v_coord;\n" @@ -512,7 +512,7 @@ TEST_P(ClearTestES3, RepeatedClear) " v_coord = texCoord;\n" "}\n"; - const std::string &fragmentSource = + constexpr char kFS[] = "#version 300 es\n" "in highp vec2 v_coord;\n" "out highp vec4 color;\n" @@ -522,7 +522,7 @@ TEST_P(ClearTestES3, RepeatedClear) " color = texture(tex, v_coord);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vertexSource, fragmentSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); mTextures.resize(1, 0); glGenTextures(1, mTextures.data()); diff --git a/src/tests/gl_tests/ClientArraysTest.cpp b/src/tests/gl_tests/ClientArraysTest.cpp index 7b2842230..6ab131888 100644 --- a/src/tests/gl_tests/ClientArraysTest.cpp +++ b/src/tests/gl_tests/ClientArraysTest.cpp @@ -76,14 +76,14 @@ TEST_P(ClientArraysTest, ForbidsClientSideElementBuffer) { ASSERT_GL_FALSE(glIsEnabled(GL_CLIENT_ARRAYS_ANGLE)); - const std::string &vert = + constexpr char kVS[] = "attribute vec3 a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); ASSERT_NE(-1, posLocation); diff --git a/src/tests/gl_tests/ComputeShaderTest.cpp b/src/tests/gl_tests/ComputeShaderTest.cpp index 03d529c2f..494729a0d 100644 --- a/src/tests/gl_tests/ComputeShaderTest.cpp +++ b/src/tests/gl_tests/ComputeShaderTest.cpp @@ -21,7 +21,7 @@ class ComputeShaderTest : public ANGLETest ComputeShaderTest() {} template - void runSharedMemoryTest(const char *csSource, + void runSharedMemoryTest(const char *kCS, GLenum internalFormat, GLenum format, const std::array &inputData, @@ -42,7 +42,7 @@ class ComputeShaderTest : public ANGLETest glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight, GL_RED_INTEGER, format, initData); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture[0], 0, GL_FALSE, 0, GL_READ_ONLY, internalFormat); @@ -88,14 +88,13 @@ class WebGL2ComputeTest : public ComputeShaderTest // link a simple compute program. It should be successful. TEST_P(ComputeShaderTest, LinkComputeProgram) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1) in; - void main() - {\ - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1) in; +void main() +{ +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); EXPECT_GL_NO_ERROR(); } @@ -104,16 +103,15 @@ TEST_P(ComputeShaderTest, LinkComputeProgram) // It should be successful. TEST_P(ComputeShaderTest, DetachShaderAfterLinkSuccess) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1) in; - void main() - { - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1) in; +void main() +{ +})"; GLuint program = glCreateProgram(); - GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource); + GLuint cs = CompileShader(GL_COMPUTE_SHADER, kCS); EXPECT_NE(0u, cs); glAttachShader(program, cs); @@ -135,13 +133,12 @@ TEST_P(ComputeShaderTest, DetachShaderAfterLinkSuccess) // link a simple compute program. There is no local size and linking should fail. TEST_P(ComputeShaderTest, LinkComputeProgramNoLocalSizeLinkError) { - const std::string csSource = - R"(#version 310 es - void main() - { - })"; + constexpr char kCS[] = R"(#version 310 es +void main() +{ +})"; - GLuint program = CompileComputeProgram(csSource, false); + GLuint program = CompileComputeProgram(kCS, false); EXPECT_EQ(0u, program); glDeleteProgram(program); @@ -153,21 +150,20 @@ TEST_P(ComputeShaderTest, LinkComputeProgramNoLocalSizeLinkError) // make sure that uniforms and uniform samplers get recorded TEST_P(ComputeShaderTest, LinkComputeProgramWithUniforms) { - const std::string csSource = - R"(#version 310 es - precision mediump sampler2D; - layout(local_size_x=1) in; - uniform int myUniformInt; - uniform sampler2D myUniformSampler; - layout(rgba32i) uniform highp writeonly iimage2D imageOut; - void main() - { - int q = myUniformInt; - vec4 v = textureLod(myUniformSampler, vec2(0.0), 0.0); - imageStore(imageOut, ivec2(0), ivec4(v) * q); - })"; + constexpr char kCS[] = R"(#version 310 es +precision mediump sampler2D; +layout(local_size_x=1) in; +uniform int myUniformInt; +uniform sampler2D myUniformSampler; +layout(rgba32i) uniform highp writeonly iimage2D imageOut; +void main() +{ + int q = myUniformInt; + vec4 v = textureLod(myUniformSampler, vec2(0.0), 0.0); + imageStore(imageOut, ivec2(0), ivec4(v) * q); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); GLint uniformLoc = glGetUniformLocation(program.get(), "myUniformInt"); EXPECT_NE(-1, uniformLoc); @@ -182,30 +178,27 @@ TEST_P(ComputeShaderTest, LinkComputeProgramWithUniforms) // OpenGL ES 3.10, 7.3 Program Objects TEST_P(ComputeShaderTest, AttachMultipleShaders) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1) in; - void main() - { - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1) in; +void main() +{ +})"; - const std::string vsSource = - R"(#version 310 es - void main() - { - })"; + constexpr char kVS[] = R"(#version 310 es +void main() +{ +})"; - const std::string fsSource = - R"(#version 310 es - void main() - { - })"; + constexpr char kFS[] = R"(#version 310 es +void main() +{ +})"; GLuint program = glCreateProgram(); - GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); - GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource); + GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); + GLuint cs = CompileShader(GL_COMPUTE_SHADER, kCS); EXPECT_NE(0u, vs); EXPECT_NE(0u, fs); @@ -234,30 +227,27 @@ TEST_P(ComputeShaderTest, AttachMultipleShaders) // Query for the number of attached shaders and check the count. TEST_P(ComputeShaderTest, AttachmentCount) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1) in; - void main() - { - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1) in; +void main() +{ +})"; - const std::string vsSource = - R"(#version 310 es - void main() - { - })"; + constexpr char kVS[] = R"(#version 310 es +void main() +{ +})"; - const std::string fsSource = - R"(#version 310 es - void main() - { - })"; + constexpr char kFS[] = R"(#version 310 es +void main() +{ +})"; GLuint program = glCreateProgram(); - GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); - GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource); + GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); + GLuint cs = CompileShader(GL_COMPUTE_SHADER, kCS); EXPECT_NE(0u, vs); EXPECT_NE(0u, fs); @@ -285,14 +275,13 @@ TEST_P(ComputeShaderTest, AttachmentCount) // Attach a compute shader and link, but start rendering. TEST_P(ComputeShaderTest, StartRenderingWithComputeProgram) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1) in; - void main() - { - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1) in; +void main() +{ +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); EXPECT_GL_NO_ERROR(); glUseProgram(program); @@ -303,22 +292,16 @@ TEST_P(ComputeShaderTest, StartRenderingWithComputeProgram) // Attach a vertex and fragment shader and link, but dispatch compute. TEST_P(ComputeShaderTest, DispatchComputeWithRenderingProgram) { - const std::string vsSource = - R"(#version 310 es - void main() - { - })"; + constexpr char kVS[] = R"(#version 310 es +void main() {})"; - const std::string fsSource = - R"(#version 310 es - void main() - { - })"; + constexpr char kFS[] = R"(#version 310 es +void main() {})"; GLuint program = glCreateProgram(); - GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); + GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); EXPECT_NE(0u, vs); EXPECT_NE(0u, fs); @@ -345,56 +328,53 @@ TEST_P(ComputeShaderTest, DispatchComputeWithRenderingProgram) // Access all compute shader special variables. TEST_P(ComputeShaderTest, AccessAllSpecialVariables) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=4, local_size_y=3, local_size_z=2) in; - layout(rgba32ui) uniform highp writeonly uimage2D imageOut; - void main() - { - uvec3 temp1 = gl_NumWorkGroups; - uvec3 temp2 = gl_WorkGroupSize; - uvec3 temp3 = gl_WorkGroupID; - uvec3 temp4 = gl_LocalInvocationID; - uvec3 temp5 = gl_GlobalInvocationID; - uint temp6 = gl_LocalInvocationIndex; - imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), uvec4(temp1 + temp2 + temp3 + temp4 + temp5, temp6)); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=4, local_size_y=3, local_size_z=2) in; +layout(rgba32ui) uniform highp writeonly uimage2D imageOut; +void main() +{ + uvec3 temp1 = gl_NumWorkGroups; + uvec3 temp2 = gl_WorkGroupSize; + uvec3 temp3 = gl_WorkGroupID; + uvec3 temp4 = gl_LocalInvocationID; + uvec3 temp5 = gl_GlobalInvocationID; + uint temp6 = gl_LocalInvocationIndex; + imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), uvec4(temp1 + temp2 + temp3 + temp4 + temp5, temp6)); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); } // Access part compute shader special variables. TEST_P(ComputeShaderTest, AccessPartSpecialVariables) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=4, local_size_y=3, local_size_z=2) in; - layout(rgba32ui) uniform highp writeonly uimage2D imageOut; - void main() - { - uvec3 temp1 = gl_WorkGroupSize; - uvec3 temp2 = gl_WorkGroupID; - uint temp3 = gl_LocalInvocationIndex; - imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), uvec4(temp1 + temp2, temp3)); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=4, local_size_y=3, local_size_z=2) in; +layout(rgba32ui) uniform highp writeonly uimage2D imageOut; +void main() +{ + uvec3 temp1 = gl_WorkGroupSize; + uvec3 temp2 = gl_WorkGroupID; + uint temp3 = gl_LocalInvocationIndex; + imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), uvec4(temp1 + temp2, temp3)); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); } // Use glDispatchCompute to define work group count. TEST_P(ComputeShaderTest, DispatchCompute) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=4, local_size_y=3, local_size_z=2) in; - layout(rgba32ui) uniform highp writeonly uimage2D imageOut; - void main() - { - uvec3 temp = gl_NumWorkGroups; - imageStore(imageOut, ivec2(0), uvec4(temp, 0u)); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=4, local_size_y=3, local_size_z=2) in; +layout(rgba32ui) uniform highp writeonly uimage2D imageOut; +void main() +{ + uvec3 temp = gl_NumWorkGroups; + imageStore(imageOut, ivec2(0), uvec4(temp, 0u)); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glDispatchCompute(8, 4, 2); @@ -406,14 +386,13 @@ TEST_P(ComputeShaderTest, DispatchComputeIndirect) { GLTexture texture; GLFramebuffer framebuffer; - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) uniform highp uimage2D uImage; - void main() - { - imageStore(uImage, ivec2(gl_WorkGroupID.x, gl_WorkGroupID.y), uvec4(100, 0, 0, 0)); - })"; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) uniform highp uimage2D uImage; +void main() +{ + imageStore(uImage, ivec2(gl_WorkGroupID.x, gl_WorkGroupID.y), uvec4(100, 0, 0, 0)); +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kCSSource); glUseProgram(program.get()); @@ -462,19 +441,18 @@ TEST_P(ComputeShaderTest, BindImageTexture) { GLTexture mTexture[2]; GLFramebuffer mFramebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) writeonly uniform highp uimage2D uImage[2]; - void main() - { - imageStore(uImage[0], ivec2(gl_LocalInvocationIndex, gl_WorkGroupID.x), uvec4(100, 0, - 0, 0)); - imageStore(uImage[1], ivec2(gl_LocalInvocationIndex, gl_WorkGroupID.x), uvec4(100, 0, - 0, 0)); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) writeonly uniform highp uimage2D uImage[2]; +void main() +{ + imageStore(uImage[0], ivec2(gl_LocalInvocationIndex, gl_WorkGroupID.x), uvec4(100, 0, +0, 0)); + imageStore(uImage[1], ivec2(gl_LocalInvocationIndex, gl_WorkGroupID.x), uvec4(100, 0, +0, 0)); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); int width = 1, height = 1; GLuint inputValues[] = {200}; @@ -536,17 +514,16 @@ TEST_P(ComputeShaderTest, ImageArrayWithoutBindingQualifier) GLTexture mTexture; GLFramebuffer mFramebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui) writeonly uniform highp uimage2D uImage[2]; - void main() - { - imageStore(uImage[0], ivec2(gl_LocalInvocationIndex, 0), uvec4(100, 0, 0, 0)); - imageStore(uImage[1], ivec2(gl_LocalInvocationIndex, 1), uvec4(100, 0, 0, 0)); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui) writeonly uniform highp uimage2D uImage[2]; +void main() +{ + imageStore(uImage[0], ivec2(gl_LocalInvocationIndex, 0), uvec4(100, 0, 0, 0)); + imageStore(uImage[1], ivec2(gl_LocalInvocationIndex, 1), uvec4(100, 0, 0, 0)); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); constexpr int kTextureWidth = 1, kTextureHeight = 2; GLuint inputValues[] = {200, 200}; @@ -581,64 +558,61 @@ TEST_P(ComputeShaderTest, ImageArrayWithoutBindingQualifier) // imageLoad functions TEST_P(ComputeShaderTest, ImageLoad) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=8) in; - layout(rgba8) uniform highp readonly image2D mImage2DInput; - layout(rgba16i) uniform highp readonly iimageCube mImageCubeInput; - layout(rgba32ui) uniform highp readonly uimage3D mImage3DInput; - layout(r32i) uniform highp writeonly iimage2D imageOut; - void main() - { - vec4 result2d = imageLoad(mImage2DInput, ivec2(gl_LocalInvocationID.xy)); - ivec4 resultCube = imageLoad(mImageCubeInput, ivec3(gl_LocalInvocationID.xyz)); - uvec4 result3d = imageLoad(mImage3DInput, ivec3(gl_LocalInvocationID.xyz)); - imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), ivec4(result2d) + resultCube + ivec4(result3d)); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=8) in; +layout(rgba8) uniform highp readonly image2D mImage2DInput; +layout(rgba16i) uniform highp readonly iimageCube mImageCubeInput; +layout(rgba32ui) uniform highp readonly uimage3D mImage3DInput; +layout(r32i) uniform highp writeonly iimage2D imageOut; +void main() +{ + vec4 result2d = imageLoad(mImage2DInput, ivec2(gl_LocalInvocationID.xy)); + ivec4 resultCube = imageLoad(mImageCubeInput, ivec3(gl_LocalInvocationID.xyz)); + uvec4 result3d = imageLoad(mImage3DInput, ivec3(gl_LocalInvocationID.xyz)); + imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), ivec4(result2d) + resultCube + ivec4(result3d)); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); EXPECT_GL_NO_ERROR(); } // imageStore functions TEST_P(ComputeShaderTest, ImageStore) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=8) in; - layout(rgba16f) uniform highp writeonly imageCube mImageCubeOutput; - layout(r32f) uniform highp writeonly image3D mImage3DOutput; - layout(rgba8ui) uniform highp writeonly uimage2DArray mImage2DArrayOutput; - void main() - { - imageStore(mImageCubeOutput, ivec3(gl_LocalInvocationID.xyz), vec4(0.0)); - imageStore(mImage3DOutput, ivec3(gl_LocalInvocationID.xyz), vec4(0.0)); - imageStore(mImage2DArrayOutput, ivec3(gl_LocalInvocationID.xyz), uvec4(0)); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=8) in; +layout(rgba16f) uniform highp writeonly imageCube mImageCubeOutput; +layout(r32f) uniform highp writeonly image3D mImage3DOutput; +layout(rgba8ui) uniform highp writeonly uimage2DArray mImage2DArrayOutput; +void main() +{ + imageStore(mImageCubeOutput, ivec3(gl_LocalInvocationID.xyz), vec4(0.0)); + imageStore(mImage3DOutput, ivec3(gl_LocalInvocationID.xyz), vec4(0.0)); + imageStore(mImage2DArrayOutput, ivec3(gl_LocalInvocationID.xyz), uvec4(0)); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); EXPECT_GL_NO_ERROR(); } // imageSize functions TEST_P(ComputeShaderTest, ImageSize) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=8) in; - layout(rgba8) uniform highp readonly imageCube mImageCubeInput; - layout(r32i) uniform highp readonly iimage2D mImage2DInput; - layout(rgba16ui) uniform highp readonly uimage2DArray mImage2DArrayInput; - layout(r32i) uniform highp writeonly iimage2D imageOut; - void main() - { - ivec2 sizeCube = imageSize(mImageCubeInput); - ivec2 size2D = imageSize(mImage2DInput); - ivec3 size2DArray = imageSize(mImage2DArrayInput); - imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), ivec4(sizeCube, size2D.x, size2DArray.x)); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=8) in; +layout(rgba8) uniform highp readonly imageCube mImageCubeInput; +layout(r32i) uniform highp readonly iimage2D mImage2DInput; +layout(rgba16ui) uniform highp readonly uimage2DArray mImage2DArrayInput; +layout(r32i) uniform highp writeonly iimage2D imageOut; +void main() +{ + ivec2 sizeCube = imageSize(mImageCubeInput); + ivec2 size2D = imageSize(mImage2DInput); + ivec3 size2DArray = imageSize(mImage2DArrayInput); + imageStore(imageOut, ivec2(gl_LocalInvocationIndex, 0), ivec4(sizeCube, size2D.x, size2DArray.x)); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); EXPECT_GL_NO_ERROR(); } @@ -647,21 +621,20 @@ TEST_P(ComputeShaderTest, TextureSampling) { ANGLE_SKIP_TEST_IF(IsD3D11()); - const std::string &csSource = - R"(#version 310 es - layout(local_size_x=16, local_size_y=16) in; - precision highp usampler2D; - uniform usampler2D tex; - layout(std140, binding = 0) buffer buf { - uint outData[16][16]; - }; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=16, local_size_y=16) in; +precision highp usampler2D; +uniform usampler2D tex; +layout(std140, binding = 0) buffer buf { + uint outData[16][16]; +}; - void main() - { - uint x = gl_LocalInvocationID.x; - uint y = gl_LocalInvocationID.y; - outData[y][x] = texelFetch(tex, ivec2(x, y), 0).x; - })"; +void main() +{ + uint x = gl_LocalInvocationID.x; + uint y = gl_LocalInvocationID.y; + outData[y][x] = texelFetch(tex, ivec2(x, y), 0).x; +})"; constexpr unsigned int kWidth = 16; constexpr unsigned int kHeight = 16; @@ -692,7 +665,7 @@ TEST_P(ComputeShaderTest, TextureSampling) glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glActiveTexture(GL_TEXTURE0); @@ -721,19 +694,18 @@ TEST_P(ComputeShaderTest, SamplingAndImageReadWrite) { GLTexture texture[3]; GLFramebuffer framebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; - precision highp usampler2D; - uniform usampler2D tex; - void main() - { - uvec4 value_1 = texelFetch(tex, ivec2(gl_LocalInvocationID.xy), 0); - uvec4 value_2 = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); - imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value_1 + value_2); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; +precision highp usampler2D; +uniform usampler2D tex; +void main() +{ + uvec4 value_1 = texelFetch(tex, ivec2(gl_LocalInvocationID.xy), 0); + uvec4 value_2 = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); + imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value_1 + value_2); +})"; constexpr int kWidth = 1, kHeight = 1; constexpr GLuint kInputValues[3][1] = {{50}, {100}, {20}}; @@ -759,7 +731,7 @@ TEST_P(ComputeShaderTest, SamplingAndImageReadWrite) EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture[0], 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32UI); @@ -791,16 +763,15 @@ TEST_P(ComputeShaderTest, BindImageTextureWithTexture2D) { GLTexture texture[2]; GLFramebuffer framebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; - void main() - { - uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); - imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; +void main() +{ + uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); + imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); +})"; constexpr int kWidth = 1, kHeight = 1; constexpr GLuint kInputValues[2][1] = {{200}, {100}}; @@ -817,7 +788,7 @@ TEST_P(ComputeShaderTest, BindImageTextureWithTexture2D) kInputValues[1]); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture[0], 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32UI); @@ -851,16 +822,15 @@ TEST_P(ComputeShaderTest, BindImageTextureWithTexture2DArray) { GLTexture texture[2]; GLFramebuffer framebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=2, local_size_y=2, local_size_z=2) in; - layout(r32ui, binding = 0) readonly uniform highp uimage2DArray uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimage2DArray uImage_2; - void main() - { - uvec4 value = imageLoad(uImage_1, ivec3(gl_LocalInvocationID.xyz)); - imageStore(uImage_2, ivec3(gl_LocalInvocationID.xyz), value); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=2, local_size_y=2, local_size_z=2) in; +layout(r32ui, binding = 0) readonly uniform highp uimage2DArray uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimage2DArray uImage_2; +void main() +{ + uvec4 value = imageLoad(uImage_1, ivec3(gl_LocalInvocationID.xyz)); + imageStore(uImage_2, ivec3(gl_LocalInvocationID.xyz), value); +})"; constexpr int kWidth = 1, kHeight = 1, kDepth = 2; constexpr GLuint kInputValues[2][2] = {{200, 200}, {100, 100}}; @@ -877,7 +847,7 @@ TEST_P(ComputeShaderTest, BindImageTextureWithTexture2DArray) GL_UNSIGNED_INT, kInputValues[1]); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture[0], 0, GL_TRUE, 0, GL_READ_ONLY, GL_R32UI); @@ -919,16 +889,15 @@ TEST_P(ComputeShaderTest, BindImageTextureWithTexture3D) { GLTexture texture[2]; GLFramebuffer framebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=2) in; - layout(r32ui, binding = 0) readonly uniform highp uimage3D uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimage3D uImage_2; - void main() - { - uvec4 value = imageLoad(uImage_1, ivec3(gl_LocalInvocationID.xyz)); - imageStore(uImage_2, ivec3(gl_LocalInvocationID.xyz), value); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=2) in; +layout(r32ui, binding = 0) readonly uniform highp uimage3D uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimage3D uImage_2; +void main() +{ + uvec4 value = imageLoad(uImage_1, ivec3(gl_LocalInvocationID.xyz)); + imageStore(uImage_2, ivec3(gl_LocalInvocationID.xyz), value); +})"; constexpr int kWidth = 1, kHeight = 1, kDepth = 2; constexpr GLuint kInputValues[2][2] = {{200, 200}, {100, 100}}; @@ -945,7 +914,7 @@ TEST_P(ComputeShaderTest, BindImageTextureWithTexture3D) GL_UNSIGNED_INT, kInputValues[1]); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture[0], 0, GL_TRUE, 0, GL_READ_ONLY, GL_R32UI); @@ -987,19 +956,18 @@ TEST_P(ComputeShaderTest, BindImageTextureWithTextureCube) { GLTexture texture[2]; GLFramebuffer framebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) readonly uniform highp uimageCube uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimageCube uImage_2; - void main() - { - for (int i = 0; i < 6; i++) - { - uvec4 value = imageLoad(uImage_1, ivec3(gl_LocalInvocationID.xy, i)); - imageStore(uImage_2, ivec3(gl_LocalInvocationID.xy, i), value); - } - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) readonly uniform highp uimageCube uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimageCube uImage_2; +void main() +{ + for (int i = 0; i < 6; i++) + { + uvec4 value = imageLoad(uImage_1, ivec3(gl_LocalInvocationID.xy, i)); + imageStore(uImage_2, ivec3(gl_LocalInvocationID.xy, i), value); + } +})"; constexpr int kWidth = 1, kHeight = 1; constexpr GLuint kInputValues[2][1] = {{200}, {100}}; @@ -1024,7 +992,7 @@ TEST_P(ComputeShaderTest, BindImageTextureWithTextureCube) } EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture[0], 0, GL_TRUE, 0, GL_READ_ONLY, GL_R32UI); @@ -1065,16 +1033,15 @@ TEST_P(ComputeShaderTest, BindImageTextureWithOneLayerTexture2DArray) GLTexture texture[2]; GLFramebuffer framebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; - void main() - { - uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); - imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; +void main() +{ + uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); + imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); +})"; constexpr int kWidth = 1, kHeight = 1, kDepth = 2; constexpr int kResultSize = kWidth * kHeight; @@ -1095,7 +1062,7 @@ TEST_P(ComputeShaderTest, BindImageTextureWithOneLayerTexture2DArray) GL_UNSIGNED_INT, kInputValues[1]); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture[0], 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32UI); @@ -1134,16 +1101,15 @@ TEST_P(ComputeShaderTest, BindImageTextureWithOneLayerTexture3D) ANGLE_SKIP_TEST_IF(IsD3D11()); GLTexture texture[2]; GLFramebuffer framebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; - void main() - { - uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); - imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; +void main() +{ + uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); + imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); +})"; constexpr int kWidth = 1, kHeight = 1, kDepth = 2; constexpr int kResultSize = kWidth * kHeight; @@ -1164,7 +1130,7 @@ TEST_P(ComputeShaderTest, BindImageTextureWithOneLayerTexture3D) GL_UNSIGNED_INT, kInputValues[1]); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture[0], 0, GL_FALSE, 1, GL_READ_ONLY, GL_R32UI); @@ -1204,16 +1170,15 @@ TEST_P(ComputeShaderTest, BindImageTextureWithOneLayerTextureCube) GLTexture texture[2]; GLFramebuffer framebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; - void main() - { - uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); - imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; +void main() +{ + uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); + imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); +})"; constexpr int kWidth = 1, kHeight = 1; constexpr int kResultSize = kWidth * kHeight; @@ -1242,7 +1207,7 @@ TEST_P(ComputeShaderTest, BindImageTextureWithOneLayerTextureCube) } EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI); @@ -1286,21 +1251,19 @@ TEST_P(ComputeShaderTest, BindImageTextureWithOneLayerTextureCube) // compute shader. TEST_P(ComputeShaderTest, QueryComputeWorkGroupSize) { - const std::string vsSource = - R"(#version 310 es - void main() - { - })"; + constexpr char kVS[] = R"(#version 310 es +void main() +{ +})"; - const std::string fsSource = - R"(#version 310 es - void main() - { - })"; + constexpr char kFS[] = R"(#version 310 es +void main() +{ +})"; GLint workGroupSize[3]; - ANGLE_GL_PROGRAM(graphicsProgram, vsSource, fsSource); + ANGLE_GL_PROGRAM(graphicsProgram, kVS, kFS); glGetProgramiv(graphicsProgram, GL_COMPUTE_WORK_GROUP_SIZE, workGroupSize); EXPECT_GL_ERROR(GL_INVALID_OPERATION); @@ -1338,36 +1301,35 @@ TEST_P(ComputeShaderTest, groupMemoryBarrierAndBarrierTest) // used to order reads/writes to variables stored in memory accessible to other shader // invocations, and barrier is used to control the relative execution order of multiple // shader invocations used to process a local work group. - const std::string csSource = - R"(#version 310 es - layout(local_size_x=2, local_size_y=2, local_size_z=1) in; - layout(r32i, binding = 0) uniform highp iimage2D image; - void main() + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=2, local_size_y=2, local_size_z=1) in; +layout(r32i, binding = 0) uniform highp iimage2D image; +void main() +{ + uint x = gl_LocalInvocationID.x; + uint y = gl_LocalInvocationID.y; + imageStore(image, ivec2(gl_LocalInvocationID.xy), ivec4(x + y)); + groupMemoryBarrier(); + barrier(); + int sum = 0; + for (int i = 0; i < 2; i++) + { + for(int j = 0; j < 2; j++) { - uint x = gl_LocalInvocationID.x; - uint y = gl_LocalInvocationID.y; - imageStore(image, ivec2(gl_LocalInvocationID.xy), ivec4(x + y)); - groupMemoryBarrier(); - barrier(); - int sum = 0; - for (int i = 0; i < 2; i++) - { - for(int j = 0; j < 2; j++) - { - sum += imageLoad(image, ivec2(i, j)).x; - } - } - groupMemoryBarrier(); - barrier(); - imageStore(image, ivec2(gl_LocalInvocationID.xy), ivec4(sum)); - })"; + sum += imageLoad(image, ivec2(i, j)).x; + } + } + groupMemoryBarrier(); + barrier(); + imageStore(image, ivec2(gl_LocalInvocationID.xy), ivec4(sum)); +})"; constexpr int kWidth = 2, kHeight = 2; glBindTexture(GL_TEXTURE_2D, texture); glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32I, kWidth, kHeight); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(0, texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32I); @@ -1458,64 +1420,62 @@ TEST_P(ComputeShaderTest, ExceedCombinedShaderOutputResourcesInCS) computeShaderStream << " instance[0].data = val + uint(val2.x);\n" "}\n"; - GLuint computeProgram = CompileComputeProgram(computeShaderStream.str()); + GLuint computeProgram = CompileComputeProgram(computeShaderStream.str().c_str()); EXPECT_EQ(0u, computeProgram); } // Test that uniform block with struct member in compute shader is supported. TEST_P(ComputeShaderTest, UniformBlockWithStructMember) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=8) in; - layout(rgba8) uniform highp readonly image2D mImage2DInput; - layout(rgba8) uniform highp writeonly image2D mImage2DOutput; - struct S { - ivec3 a; - ivec2 b; - }; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=8) in; +layout(rgba8) uniform highp readonly image2D mImage2DInput; +layout(rgba8) uniform highp writeonly image2D mImage2DOutput; +struct S { + ivec3 a; + ivec2 b; +}; - layout(std140, binding=0) uniform blockName { - S bd; - } instanceName; - void main() - { - ivec2 t1 = instanceName.bd.b; - vec4 result2d = imageLoad(mImage2DInput, t1); - imageStore(mImage2DOutput, ivec2(gl_LocalInvocationID.xy), result2d); - })"; +layout(std140, binding=0) uniform blockName { + S bd; +} instanceName; +void main() +{ + ivec2 t1 = instanceName.bd.b; + vec4 result2d = imageLoad(mImage2DInput, t1); + imageStore(mImage2DOutput, ivec2(gl_LocalInvocationID.xy), result2d); +})"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); EXPECT_GL_NO_ERROR(); } // Verify shared non-array variables can work correctly. TEST_P(ComputeShaderTest, NonArraySharedVariable) { - const char kCSShader[] = - R"(#version 310 es - layout (local_size_x = 2, local_size_y = 2, local_size_z = 1) in; - layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; - layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; - shared uint temp; - void main() - { - if (gl_LocalInvocationID == uvec3(0, 0, 0)) - { - temp = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; - } - groupMemoryBarrier(); - barrier(); - if (gl_LocalInvocationID == uvec3(1, 1, 0)) - { - imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), uvec4(temp)); - } - else - { - uint inputValue = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; - imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), uvec4(inputValue)); - } - })"; + const char kCSShader[] = R"(#version 310 es +layout (local_size_x = 2, local_size_y = 2, local_size_z = 1) in; +layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; +layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; +shared uint temp; +void main() +{ + if (gl_LocalInvocationID == uvec3(0, 0, 0)) + { + temp = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; + } + groupMemoryBarrier(); + barrier(); + if (gl_LocalInvocationID == uvec3(1, 1, 0)) + { + imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), uvec4(temp)); + } + else + { + uint inputValue = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; + imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), uvec4(inputValue)); + } +})"; const std::array inputData = {{250, 200, 150, 100}}; const std::array expectedValues = {{250, 200, 150, 250}}; @@ -1526,21 +1486,20 @@ TEST_P(ComputeShaderTest, NonArraySharedVariable) // Verify shared non-struct array variables can work correctly. TEST_P(ComputeShaderTest, NonStructArrayAsSharedVariable) { - const char kCSShader[] = - R"(#version 310 es - layout (local_size_x = 2, local_size_y = 2, local_size_z = 1) in; - layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; - layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; - shared uint sharedData[2][2]; - void main() - { - uint inputData = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; - sharedData[gl_LocalInvocationID.x][gl_LocalInvocationID.y] = inputData; - groupMemoryBarrier(); - barrier(); - imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), - uvec4(sharedData[gl_LocalInvocationID.y][gl_LocalInvocationID.x])); - })"; + const char kCSShader[] = R"(#version 310 es +layout (local_size_x = 2, local_size_y = 2, local_size_z = 1) in; +layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; +layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; +shared uint sharedData[2][2]; +void main() +{ + uint inputData = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; + sharedData[gl_LocalInvocationID.x][gl_LocalInvocationID.y] = inputData; + groupMemoryBarrier(); + barrier(); + imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), + uvec4(sharedData[gl_LocalInvocationID.y][gl_LocalInvocationID.x])); +})"; const std::array inputData = {{250, 200, 150, 100}}; const std::array expectedValues = {{250, 150, 200, 100}}; @@ -1551,25 +1510,24 @@ TEST_P(ComputeShaderTest, NonStructArrayAsSharedVariable) // Verify shared struct array variables work correctly. TEST_P(ComputeShaderTest, StructArrayAsSharedVariable) { - const char kCSShader[] = - R"(#version 310 es - layout (local_size_x = 2, local_size_y = 2, local_size_z = 1) in; - layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; - layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; - struct SharedStruct - { - uint data; - }; - shared SharedStruct sharedData[2][2]; - void main() - { - uint inputData = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; - sharedData[gl_LocalInvocationID.x][gl_LocalInvocationID.y].data = inputData; - groupMemoryBarrier(); - barrier(); - imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), - uvec4(sharedData[gl_LocalInvocationID.y][gl_LocalInvocationID.x].data)); - })"; + const char kCSShader[] = R"(#version 310 es +layout (local_size_x = 2, local_size_y = 2, local_size_z = 1) in; +layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; +layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; +struct SharedStruct +{ + uint data; +}; +shared SharedStruct sharedData[2][2]; +void main() +{ + uint inputData = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; + sharedData[gl_LocalInvocationID.x][gl_LocalInvocationID.y].data = inputData; + groupMemoryBarrier(); + barrier(); + imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), + uvec4(sharedData[gl_LocalInvocationID.y][gl_LocalInvocationID.x].data)); +})"; const std::array inputData = {{250, 200, 150, 100}}; const std::array expectedValues = {{250, 150, 200, 100}}; @@ -1584,55 +1542,54 @@ TEST_P(ComputeShaderTest, AtomicFunctionsNoReturnValue) // bot. ANGLE_SKIP_TEST_IF(IsAndroid()); - const char kCSShader[] = - R"(#version 310 es - layout (local_size_x = 8, local_size_y = 1, local_size_z = 1) in; - layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; - layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; + const char kCSShader[] = R"(#version 310 es +layout (local_size_x = 8, local_size_y = 1, local_size_z = 1) in; +layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; +layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; - const uint kSumIndex = 0u; - const uint kMinIndex = 1u; - const uint kMaxIndex = 2u; - const uint kOrIndex = 3u; - const uint kAndIndex = 4u; - const uint kXorIndex = 5u; - const uint kExchangeIndex = 6u; - const uint kCompSwapIndex = 7u; +const uint kSumIndex = 0u; +const uint kMinIndex = 1u; +const uint kMaxIndex = 2u; +const uint kOrIndex = 3u; +const uint kAndIndex = 4u; +const uint kXorIndex = 5u; +const uint kExchangeIndex = 6u; +const uint kCompSwapIndex = 7u; - shared highp uint results[8]; +shared highp uint results[8]; - void main() - { - if (gl_LocalInvocationID.x == kMinIndex || gl_LocalInvocationID.x == kAndIndex) - { - results[gl_LocalInvocationID.x] = 0xFFFFu; - } - else if (gl_LocalInvocationID.x == kCompSwapIndex) - { - results[gl_LocalInvocationID.x] = 1u; - } - else - { - results[gl_LocalInvocationID.x] = 0u; - } - memoryBarrierShared(); - barrier(); +void main() +{ + if (gl_LocalInvocationID.x == kMinIndex || gl_LocalInvocationID.x == kAndIndex) + { + results[gl_LocalInvocationID.x] = 0xFFFFu; + } + else if (gl_LocalInvocationID.x == kCompSwapIndex) + { + results[gl_LocalInvocationID.x] = 1u; + } + else + { + results[gl_LocalInvocationID.x] = 0u; + } + memoryBarrierShared(); + barrier(); - uint value = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; - atomicAdd(results[kSumIndex], value); - atomicMin(results[kMinIndex], value); - atomicMax(results[kMaxIndex], value); - atomicOr(results[kOrIndex], value); - atomicAnd(results[kAndIndex], value); - atomicXor(results[kXorIndex], value); - atomicExchange(results[kExchangeIndex], value); - atomicCompSwap(results[kCompSwapIndex], value, 256u); - memoryBarrierShared(); - barrier(); + uint value = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; + atomicAdd(results[kSumIndex], value); + atomicMin(results[kMinIndex], value); + atomicMax(results[kMaxIndex], value); + atomicOr(results[kOrIndex], value); + atomicAnd(results[kAndIndex], value); + atomicXor(results[kXorIndex], value); + atomicExchange(results[kExchangeIndex], value); + atomicCompSwap(results[kCompSwapIndex], value, 256u); + memoryBarrierShared(); + barrier(); - imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), - uvec4(results[gl_LocalInvocationID.x])); - })"; + imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), + uvec4(results[gl_LocalInvocationID.x])); +})"; const std::array inputData = {{1, 2, 4, 8, 16, 32, 64, 128}}; const std::array expectedValues = {{255, 1, 128, 255, 0, 255, 128, 256}}; @@ -1643,44 +1600,43 @@ TEST_P(ComputeShaderTest, AtomicFunctionsNoReturnValue) // Verify using atomic functions in a non-initializer single assignment can work correctly. TEST_P(ComputeShaderTest, AtomicFunctionsInNonInitializerSingleAssignment) { - const char kCSShader[] = - R"(#version 310 es - layout (local_size_x = 9, local_size_y = 1, local_size_z = 1) in; - layout (r32i, binding = 0) readonly uniform highp iimage2D srcImage; - layout (r32i, binding = 1) writeonly uniform highp iimage2D dstImage; + const char kCSShader[] = R"(#version 310 es +layout (local_size_x = 9, local_size_y = 1, local_size_z = 1) in; +layout (r32i, binding = 0) readonly uniform highp iimage2D srcImage; +layout (r32i, binding = 1) writeonly uniform highp iimage2D dstImage; - shared highp int sharedVariable; +shared highp int sharedVariable; - shared highp int inputData[9]; - shared highp int outputData[9]; +shared highp int inputData[9]; +shared highp int outputData[9]; - void main() - { - int inputValue = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; - inputData[gl_LocalInvocationID.x] = inputValue; - memoryBarrierShared(); - barrier(); +void main() +{ + int inputValue = imageLoad(srcImage, ivec2(gl_LocalInvocationID.xy)).x; + inputData[gl_LocalInvocationID.x] = inputValue; + memoryBarrierShared(); + barrier(); - if (gl_LocalInvocationID.x == 0u) - { - sharedVariable = 0; + if (gl_LocalInvocationID.x == 0u) + { + sharedVariable = 0; - outputData[0] = atomicAdd(sharedVariable, inputData[0]); - outputData[1] = atomicMin(sharedVariable, inputData[1]); - outputData[2] = atomicMax(sharedVariable, inputData[2]); - outputData[3] = atomicAnd(sharedVariable, inputData[3]); - outputData[4] = atomicOr(sharedVariable, inputData[4]); - outputData[5] = atomicXor(sharedVariable, inputData[5]); - outputData[6] = atomicExchange(sharedVariable, inputData[6]); - outputData[7] = atomicCompSwap(sharedVariable, 64, inputData[7]); - outputData[8] = atomicAdd(sharedVariable, inputData[8]); - } - memoryBarrierShared(); - barrier(); + outputData[0] = atomicAdd(sharedVariable, inputData[0]); + outputData[1] = atomicMin(sharedVariable, inputData[1]); + outputData[2] = atomicMax(sharedVariable, inputData[2]); + outputData[3] = atomicAnd(sharedVariable, inputData[3]); + outputData[4] = atomicOr(sharedVariable, inputData[4]); + outputData[5] = atomicXor(sharedVariable, inputData[5]); + outputData[6] = atomicExchange(sharedVariable, inputData[6]); + outputData[7] = atomicCompSwap(sharedVariable, 64, inputData[7]); + outputData[8] = atomicAdd(sharedVariable, inputData[8]); + } + memoryBarrierShared(); + barrier(); - imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), - ivec4(outputData[gl_LocalInvocationID.x])); - })"; + imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), + ivec4(outputData[gl_LocalInvocationID.x])); +})"; const std::array inputData = {{1, 2, 4, 8, 16, 32, 64, 128, 1}}; const std::array expectedValues = {{0, 1, 1, 4, 0, 16, 48, 64, 128}}; @@ -1690,8 +1646,7 @@ TEST_P(ComputeShaderTest, AtomicFunctionsInNonInitializerSingleAssignment) // Verify using atomic functions in an initializers and using unsigned int works correctly. TEST_P(ComputeShaderTest, AtomicFunctionsInitializerWithUnsigned) { - constexpr char kCShader[] = - R"(#version 310 es + constexpr char kCShader[] = R"(#version 310 es layout (local_size_x = 9, local_size_y = 1, local_size_z = 1) in; layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; @@ -1748,8 +1703,7 @@ void main() // Verify using atomic functions inside expressions as unsigned int. TEST_P(ComputeShaderTest, AtomicFunctionsReturnWithUnsigned) { - constexpr char kCShader[] = - R"(#version 310 es + constexpr char kCShader[] = R"(#version 310 es layout (local_size_x = 9, local_size_y = 1, local_size_z = 1) in; layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; @@ -1796,8 +1750,7 @@ void main() // Verify using nested atomic functions in expressions. TEST_P(ComputeShaderTest, AtomicFunctionsReturnWithMultipleTypes) { - constexpr char kCShader[] = - R"(#version 310 es + constexpr char kCShader[] = R"(#version 310 es layout (local_size_x = 4, local_size_y = 1, local_size_z = 1) in; layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; @@ -1845,18 +1798,17 @@ TEST_P(ComputeShaderTest, UniformBuffer) GLTexture texture; GLBuffer buffer; GLFramebuffer framebuffer; - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - uniform uni - { - uvec4 value; - }; - layout(rgba32ui, binding = 0) writeonly uniform highp uimage2D uImage; - void main() - { - imageStore(uImage, ivec2(gl_LocalInvocationID.xy), value); - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +uniform uni +{ + uvec4 value; +}; +layout(rgba32ui, binding = 0) writeonly uniform highp uimage2D uImage; +void main() +{ + imageStore(uImage, ivec2(gl_LocalInvocationID.xy), value); +})"; constexpr int kWidth = 1, kHeight = 1; constexpr GLuint kInputValues[4] = {56, 57, 58, 59}; @@ -1867,7 +1819,7 @@ TEST_P(ComputeShaderTest, UniformBuffer) kInputValues); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "uni"); @@ -1904,16 +1856,15 @@ TEST_P(ComputeShaderTest, UniformBuffer) // Test that storing data to image and then loading the same image data works correctly. TEST_P(ComputeShaderTest, StoreImageThenLoad) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; - void main() - { - uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); - imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); - })"; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; +void main() +{ + uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); + imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); +})"; constexpr GLuint kInputValues[3][1] = {{300}, {200}, {100}}; GLTexture texture[3]; @@ -1962,16 +1913,15 @@ TEST_P(ComputeShaderTest, StoreImageThenLoad) // Test that loading image data and then storing data to the same image works correctly. TEST_P(ComputeShaderTest, LoadImageThenStore) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; - layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; - void main() - { - uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); - imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); - })"; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1; +layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2; +void main() +{ + uvec4 value = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy)); + imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value); +})"; constexpr GLuint kInputValues[3][1] = {{300}, {200}, {100}}; GLTexture texture[3]; @@ -2020,22 +1970,21 @@ TEST_P(ComputeShaderTest, LoadImageThenStore) // Test that scalar buffer variables are supported. TEST_P(ComputeShaderTest, ShaderStorageBlocksScalar) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=1) in; - layout(std140, binding = 0) buffer blockA { - uvec3 uv; - float f; - } instanceA; - layout(std140, binding = 1) buffer blockB { - vec2 v; - uint u[3]; - float f; - }; - void main() - { - f = instanceA.f; - })"; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=1) in; +layout(std140, binding = 0) buffer blockA { + uvec3 uv; + float f; +} instanceA; +layout(std140, binding = 1) buffer blockB { + vec2 v; + uint u[3]; + float f; +}; +void main() +{ + f = instanceA.f; +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kCSSource); EXPECT_GL_NO_ERROR(); @@ -2044,19 +1993,18 @@ TEST_P(ComputeShaderTest, ShaderStorageBlocksScalar) // Test that vector buffer variables are supported. TEST_P(ComputeShaderTest, ShaderStorageBlocksVector) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=1) in; - layout(std140, binding = 0) buffer blockA { - vec2 f; - } instanceA; - layout(std140, binding = 1) buffer blockB { - vec3 f; - }; - void main() - { - f[1] = instanceA.f[0]; - })"; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=1) in; +layout(std140, binding = 0) buffer blockA { + vec2 f; +} instanceA; +layout(std140, binding = 1) buffer blockB { + vec3 f; +}; +void main() +{ + f[1] = instanceA.f[0]; +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kCSSource); EXPECT_GL_NO_ERROR(); @@ -2065,19 +2013,18 @@ TEST_P(ComputeShaderTest, ShaderStorageBlocksVector) // Test that matrix buffer variables are supported. TEST_P(ComputeShaderTest, ShaderStorageBlocksMatrix) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=1) in; - layout(std140, binding = 0) buffer blockA { - mat3x4 m; - } instanceA; - layout(std140, binding = 1) buffer blockB { - mat3x4 m; - }; - void main() - { - m[0][1] = instanceA.m[0][1]; - })"; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=1) in; +layout(std140, binding = 0) buffer blockA { + mat3x4 m; +} instanceA; +layout(std140, binding = 1) buffer blockB { + mat3x4 m; +}; +void main() +{ + m[0][1] = instanceA.m[0][1]; +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kCSSource); EXPECT_GL_NO_ERROR(); @@ -2086,19 +2033,18 @@ TEST_P(ComputeShaderTest, ShaderStorageBlocksMatrix) // Test that scalar array buffer variables are supported. TEST_P(ComputeShaderTest, ShaderStorageBlocksScalarArray) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=8) in; - layout(std140, binding = 0) buffer blockA { - float f[8]; - } instanceA; - layout(std140, binding = 1) buffer blockB { - float f[8]; - }; - void main() - { - f[gl_LocalInvocationIndex] = instanceA.f[gl_LocalInvocationIndex]; - })"; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=8) in; +layout(std140, binding = 0) buffer blockA { + float f[8]; +} instanceA; +layout(std140, binding = 1) buffer blockB { + float f[8]; +}; +void main() +{ + f[gl_LocalInvocationIndex] = instanceA.f[gl_LocalInvocationIndex]; +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kCSSource); EXPECT_GL_NO_ERROR(); @@ -2107,19 +2053,18 @@ TEST_P(ComputeShaderTest, ShaderStorageBlocksScalarArray) // Test that vector array buffer variables are supported. TEST_P(ComputeShaderTest, ShaderStorageBlocksVectorArray) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=4) in; - layout(std140, binding = 0) buffer blockA { - vec2 v[4]; - } instanceA; - layout(std140, binding = 1) buffer blockB { - vec4 v[4]; - }; - void main() - { - v[0][gl_LocalInvocationIndex] = instanceA.v[gl_LocalInvocationIndex][1]; - })"; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=4) in; +layout(std140, binding = 0) buffer blockA { + vec2 v[4]; +} instanceA; +layout(std140, binding = 1) buffer blockB { + vec4 v[4]; +}; +void main() +{ + v[0][gl_LocalInvocationIndex] = instanceA.v[gl_LocalInvocationIndex][1]; +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kCSSource); EXPECT_GL_NO_ERROR(); @@ -2128,22 +2073,21 @@ TEST_P(ComputeShaderTest, ShaderStorageBlocksVectorArray) // Test that matrix array buffer variables are supported. TEST_P(ComputeShaderTest, ShaderStorageBlocksMatrixArray) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=8) in; - layout(std140, binding = 0) buffer blockA { - float v1[5]; - mat4 m[8]; - } instanceA; - layout(std140, binding = 1) buffer blockB { - vec2 v1[3]; - mat4 m[8]; - }; - void main() - { - float data = instanceA.m[gl_LocalInvocationIndex][0][0]; - m[gl_LocalInvocationIndex][gl_LocalInvocationIndex][gl_LocalInvocationIndex] = data; - })"; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=8) in; +layout(std140, binding = 0) buffer blockA { + float v1[5]; + mat4 m[8]; +} instanceA; +layout(std140, binding = 1) buffer blockB { + vec2 v1[3]; + mat4 m[8]; +}; +void main() +{ + float data = instanceA.m[gl_LocalInvocationIndex][0][0]; + m[gl_LocalInvocationIndex][gl_LocalInvocationIndex][gl_LocalInvocationIndex] = data; +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kCSSource); EXPECT_GL_NO_ERROR(); @@ -2152,21 +2096,19 @@ TEST_P(ComputeShaderTest, ShaderStorageBlocksMatrixArray) // Test that shader storage blocks only in assignment right is supported. TEST_P(ComputeShaderTest, ShaderStorageBlocksInAssignmentRight) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=8) in; - layout(std140, binding = 0) buffer blockA { - float data[8]; - } instanceA; - layout(r32f, binding = 0) writeonly uniform highp image2D imageOut; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=8) in; +layout(std140, binding = 0) buffer blockA { + float data[8]; +} instanceA; +layout(r32f, binding = 0) writeonly uniform highp image2D imageOut; - void main() - { - float data = 1.0; - data = instanceA.data[gl_LocalInvocationIndex]; - imageStore(imageOut, ivec2(gl_LocalInvocationID.xy), vec4(data)); - } - )"; +void main() +{ + float data = 1.0; + data = instanceA.data[gl_LocalInvocationIndex]; + imageStore(imageOut, ivec2(gl_LocalInvocationID.xy), vec4(data)); +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kCSSource); EXPECT_GL_NO_ERROR(); @@ -2175,22 +2117,21 @@ TEST_P(ComputeShaderTest, ShaderStorageBlocksInAssignmentRight) // Test that shader storage blocks with unsized array are supported. TEST_P(ComputeShaderTest, ShaderStorageBlocksWithUnsizedArray) { - const char kCSSource[] = - R"(#version 310 es - layout(local_size_x=8) in; - layout(std140, binding = 0) buffer blockA { - float v[]; - } instanceA; - layout(std140, binding = 0) buffer blockB { - float v[]; - } instanceB[1]; + const char kCSSource[] = R"(#version 310 es +layout(local_size_x=8) in; +layout(std140, binding = 0) buffer blockA { + float v[]; +} instanceA; +layout(std140, binding = 0) buffer blockB { + float v[]; +} instanceB[1]; - void main() - { - float data = instanceA.v[gl_LocalInvocationIndex]; - instanceB[0].v[gl_LocalInvocationIndex * 2u + 1u] = data; - } - )"; +void main() +{ + float data = instanceA.v[gl_LocalInvocationIndex]; + instanceB[0].v[gl_LocalInvocationIndex * 2u + 1u] = data; +} +)"; ANGLE_GL_COMPUTE_PROGRAM(program, kCSSource); EXPECT_GL_NO_ERROR(); @@ -2200,26 +2141,24 @@ TEST_P(ComputeShaderTest, ShaderStorageBlocksWithUnsizedArray) // don't need to calculate the offset and should be translated by OutputHLSL directly. TEST_P(ComputeShaderTest, IndexAndDotOperatorsInSSBOIndexIndirectOperator) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es - layout(local_size_x=1) in; - layout(std140, binding = 0) buffer blockA { - float v[4]; - }; - layout(std140, binding = 1) buffer blockB { - float v[4]; - } instanceB[1]; - struct S - { - uvec4 index[2]; - } s; - void main() - { - s.index[0] = uvec4(0u, 1u, 2u, 3u); - float data = v[s.index[0].y]; - instanceB[0].v[s.index[0].x] = data; - } - )"; + constexpr char kComputeShaderSource[] = R"(#version 310 es +layout(local_size_x=1) in; +layout(std140, binding = 0) buffer blockA { + float v[4]; +}; +layout(std140, binding = 1) buffer blockB { + float v[4]; +} instanceB[1]; +struct S +{ + uvec4 index[2]; +} s; +void main() +{ + s.index[0] = uvec4(0u, 1u, 2u, 3u); + float data = v[s.index[0].y]; + instanceB[0].v[s.index[0].x] = data; +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource); EXPECT_GL_NO_ERROR(); @@ -2228,22 +2167,20 @@ TEST_P(ComputeShaderTest, IndexAndDotOperatorsInSSBOIndexIndirectOperator) // Test that swizzle node in non-SSBO symbol works well. TEST_P(ComputeShaderTest, ShaderStorageBlocksWithNonSSBOSwizzle) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es - layout(local_size_x=8) in; - layout(std140, binding = 0) buffer blockA { - float v[8]; - }; - layout(std140, binding = 1) buffer blockB { - float v[8]; - } instanceB[1]; + constexpr char kComputeShaderSource[] = R"(#version 310 es +layout(local_size_x=8) in; +layout(std140, binding = 0) buffer blockA { + float v[8]; +}; +layout(std140, binding = 1) buffer blockB { + float v[8]; +} instanceB[1]; - void main() - { - float data = v[gl_GlobalInvocationID.x]; - instanceB[0].v[gl_GlobalInvocationID.x] = data; - } - )"; +void main() +{ + float data = v[gl_GlobalInvocationID.x]; + instanceB[0].v[gl_GlobalInvocationID.x] = data; +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource); EXPECT_GL_NO_ERROR(); @@ -2252,21 +2189,19 @@ TEST_P(ComputeShaderTest, ShaderStorageBlocksWithNonSSBOSwizzle) // Test that swizzle node in SSBO symbol works well. TEST_P(ComputeShaderTest, ShaderStorageBlocksWithSSBOSwizzle) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es - layout(local_size_x=1) in; - layout(std140, binding = 0) buffer blockA { - vec2 v; - }; - layout(std140, binding = 1) buffer blockB { - float v; - } instanceB[1]; + constexpr char kComputeShaderSource[] = R"(#version 310 es +layout(local_size_x=1) in; +layout(std140, binding = 0) buffer blockA { + vec2 v; +}; +layout(std140, binding = 1) buffer blockB { + float v; +} instanceB[1]; - void main() - { - instanceB[0].v = v.x; - } - )"; +void main() +{ + instanceB[0].v = v.x; +})"; ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource); EXPECT_GL_NO_ERROR(); @@ -2284,36 +2219,35 @@ TEST_P(ComputeShaderTestES3, NotSupported) // The contents of shared variables should be cleared to zero at the beginning of shader execution. TEST_P(WebGL2ComputeTest, sharedVariablesShouldBeZero) { - const char kCSShader[] = - R"(#version 310 es - layout (local_size_x = 4, local_size_y = 4, local_size_z = 1) in; - layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; - layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; - struct S { - float f; - int i; - uint u; - bool b; - vec4 v[64]; - }; + const char kCSShader[] = R"(#version 310 es +layout (local_size_x = 4, local_size_y = 4, local_size_z = 1) in; +layout (r32ui, binding = 0) readonly uniform highp uimage2D srcImage; +layout (r32ui, binding = 1) writeonly uniform highp uimage2D dstImage; +struct S { + float f; + int i; + uint u; + bool b; + vec4 v[64]; +}; - shared S vars[16]; - void main() - { - S zeroS; - zeroS.f = 0.0f; - zeroS.i = 0; - zeroS.u = 0u; - zeroS.b = false; - for (int i = 0; i < 64; i++) - { - zeroS.v[i] = vec4(0.0f); - } +shared S vars[16]; +void main() +{ + S zeroS; + zeroS.f = 0.0f; + zeroS.i = 0; + zeroS.u = 0u; + zeroS.b = false; + for (int i = 0; i < 64; i++) + { + zeroS.v[i] = vec4(0.0f); + } - uint tid = gl_LocalInvocationID.x + gl_LocalInvocationID.y * 4u; - uint value = (zeroS == vars[tid] ? 127u : 0u); - imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), uvec4(value)); - })"; + uint tid = gl_LocalInvocationID.x + gl_LocalInvocationID.y * 4u; + uint value = (zeroS == vars[tid] ? 127u : 0u); + imageStore(dstImage, ivec2(gl_LocalInvocationID.xy), uvec4(value)); +})"; const std::array inputData = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; const std::array expectedValues = { diff --git a/src/tests/gl_tests/CopyCompressedTextureTest.cpp b/src/tests/gl_tests/CopyCompressedTextureTest.cpp index d233eed40..d15f36b95 100644 --- a/src/tests/gl_tests/CopyCompressedTextureTest.cpp +++ b/src/tests/gl_tests/CopyCompressedTextureTest.cpp @@ -30,21 +30,25 @@ class CopyCompressedTextureTest : public ANGLETest glGenTextures(2, mTextures); - mProgram = CompileProgram( + constexpr char kVS[] = "attribute vec2 a_position;\n" "varying vec2 v_texcoord;\n" "void main()\n" "{\n" " gl_Position = vec4(a_position, 0.0, 1.0);\n" " v_texcoord = (a_position + 1.0) * 0.5;\n" - "}\n", + "}\n"; + + constexpr char kFS[] = "precision mediump float;\n" "uniform sampler2D u_texture;\n" "varying vec2 v_texcoord;\n" "void main()\n" "{\n" " gl_FragColor = texture2D(u_texture, v_texcoord);\n" - "}\n"); + "}\n"; + + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); if (extensionEnabled("GL_CHROMIUM_copy_compressed_texture")) diff --git a/src/tests/gl_tests/CopyTexImageTest.cpp b/src/tests/gl_tests/CopyTexImageTest.cpp index 08d9e0c56..eb6d2d16e 100644 --- a/src/tests/gl_tests/CopyTexImageTest.cpp +++ b/src/tests/gl_tests/CopyTexImageTest.cpp @@ -87,7 +87,7 @@ class CopyTexImageTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vsSource = + constexpr char kVS[] = "precision highp float;\n" "attribute vec4 position;\n" "varying vec2 texcoord;\n" @@ -99,7 +99,7 @@ class CopyTexImageTest : public ANGLETest " texcoord.y = 1.0 - texcoord.y;\n" "}\n"; - const std::string textureFSSource = + constexpr char kFS[] = "precision highp float;\n" "uniform sampler2D tex;\n" "varying vec2 texcoord;\n" @@ -109,7 +109,7 @@ class CopyTexImageTest : public ANGLETest " gl_FragColor = texture2D(tex, texcoord);\n" "}\n"; - mTextureProgram = CompileProgram(vsSource, textureFSSource); + mTextureProgram = CompileProgram(kVS, kFS); if (mTextureProgram == 0) { FAIL() << "shader compilation failed."; diff --git a/src/tests/gl_tests/CopyTexture3DTest.cpp b/src/tests/gl_tests/CopyTexture3DTest.cpp index da8c08dba..47a68e673 100644 --- a/src/tests/gl_tests/CopyTexture3DTest.cpp +++ b/src/tests/gl_tests/CopyTexture3DTest.cpp @@ -38,8 +38,8 @@ class CopyTexture3DTest : public ANGLETest eglGetProcAddress("glCopySubTexture3DANGLE")); } - const std::string vertexShaderSource = getVertexShaderSource(); - const std::string fragmentShaderSource = getFragmentShaderSource(); + const char *vertexShaderSource = getVertexShaderSource(); + const char *fragmentShaderSource = getFragmentShaderSource(); mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); ASSERT_NE(0u, mProgram); @@ -49,17 +49,16 @@ class CopyTexture3DTest : public ANGLETest ASSERT_GL_NO_ERROR(); } - std::string getVertexShaderSource() + const char *getVertexShaderSource() { - return std::string( - "#version 300 es\n" - "out vec3 texcoord;\n" - "in vec4 position;\n" - "void main()\n" - "{\n" - " gl_Position = vec4(position.xy, 0.0, 1.0);\n" - " texcoord = (position.xyz * 0.5) + 0.5;\n" - "}\n"); + return "#version 300 es\n" + "out vec3 texcoord;\n" + "in vec4 position;\n" + "void main()\n" + "{\n" + " gl_Position = vec4(position.xy, 0.0, 1.0);\n" + " texcoord = (position.xyz * 0.5) + 0.5;\n" + "}\n"; } void TearDown() override { ANGLETest::TearDown(); } @@ -231,7 +230,7 @@ class CopyTexture3DTest : public ANGLETest } } - virtual std::string getFragmentShaderSource() = 0; + virtual const char *getFragmentShaderSource() = 0; GLuint mProgram = 0; GLTexture sourceTexture; @@ -246,18 +245,17 @@ class Texture3DCopy : public CopyTexture3DTest protected: Texture3DCopy() {} - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp sampler3D tex3D;\n" - "in vec3 texcoord;\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " fragColor = texture(tex3D, vec3(texcoord.x, texcoord.z, texcoord.y));\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp sampler3D tex3D;\n" + "in vec3 texcoord;\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " fragColor = texture(tex3D, vec3(texcoord.x, texcoord.z, texcoord.y));\n" + "}\n"; } }; @@ -266,18 +264,17 @@ class Texture2DArrayCopy : public CopyTexture3DTest protected: Texture2DArrayCopy() {} - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp sampler2DArray tex2DArray;\n" - "in vec3 texcoord;\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.z, texcoord.y));\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp sampler2DArray tex2DArray;\n" + "in vec3 texcoord;\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.z, texcoord.y));\n" + "}\n"; } }; @@ -784,7 +781,7 @@ TEST_P(Texture3DCopy, IntFormats) { ANGLE_SKIP_TEST_IF(!checkExtensions()); - std::string fragmentShader( + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "uniform highp isampler3D tex3D;\n" @@ -793,9 +790,9 @@ TEST_P(Texture3DCopy, IntFormats) "void main()\n" "{\n" " fragColor = texture(tex3D, vec3(texcoord.x, texcoord.z, texcoord.y));\n" - "}\n"); + "}\n"; - mProgram = CompileProgram(getVertexShaderSource(), fragmentShader); + mProgram = CompileProgram(getVertexShaderSource(), kFS); ASSERT_NE(0u, mProgram); ASSERT_GL_NO_ERROR(); @@ -894,7 +891,7 @@ TEST_P(Texture3DCopy, UintFormats) { ANGLE_SKIP_TEST_IF(!checkExtensions()); - std::string fragmentShader( + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "uniform highp usampler3D tex3D;\n" @@ -903,9 +900,9 @@ TEST_P(Texture3DCopy, UintFormats) "void main()\n" "{\n" " fragColor = texture(tex3D, vec3(texcoord.x, texcoord.z, texcoord.y));\n" - "}\n"); + "}\n"; - mProgram = CompileProgram(getVertexShaderSource(), fragmentShader); + mProgram = CompileProgram(getVertexShaderSource(), kFS); ASSERT_NE(0u, mProgram); ASSERT_GL_NO_ERROR(); @@ -1523,7 +1520,7 @@ TEST_P(Texture2DArrayCopy, IntFormats) { ANGLE_SKIP_TEST_IF(!checkExtensions()); - std::string fragmentShader( + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "uniform highp isampler2DArray tex2DArray;\n" @@ -1532,9 +1529,9 @@ TEST_P(Texture2DArrayCopy, IntFormats) "void main()\n" "{\n" " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.z, texcoord.y));\n" - "}\n"); + "}\n"; - mProgram = CompileProgram(getVertexShaderSource(), fragmentShader); + mProgram = CompileProgram(getVertexShaderSource(), kFS); ASSERT_NE(0u, mProgram); ASSERT_GL_NO_ERROR(); @@ -1633,7 +1630,7 @@ TEST_P(Texture2DArrayCopy, UintFormats) { ANGLE_SKIP_TEST_IF(!checkExtensions()); - std::string fragmentShader( + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "uniform highp usampler2DArray tex2DArray;\n" @@ -1642,9 +1639,9 @@ TEST_P(Texture2DArrayCopy, UintFormats) "void main()\n" "{\n" " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.z, texcoord.y));\n" - "}\n"); + "}\n"; - mProgram = CompileProgram(getVertexShaderSource(), fragmentShader); + mProgram = CompileProgram(getVertexShaderSource(), kFS); ASSERT_NE(0u, mProgram); ASSERT_GL_NO_ERROR(); diff --git a/src/tests/gl_tests/CopyTextureTest.cpp b/src/tests/gl_tests/CopyTextureTest.cpp index 4ef46ff64..4f1ac478c 100644 --- a/src/tests/gl_tests/CopyTextureTest.cpp +++ b/src/tests/gl_tests/CopyTextureTest.cpp @@ -1222,7 +1222,7 @@ TEST_P(CopyTextureTestES3, ES3UnormFormats) } auto testOutput = [this](GLuint texture, const GLColor &expectedColor) { - const std::string vs = + constexpr char kVS[] = "#version 300 es\n" "in vec4 position;\n" "out vec2 texcoord;\n" @@ -1232,7 +1232,7 @@ TEST_P(CopyTextureTestES3, ES3UnormFormats) " texcoord = (position.xy * 0.5) + 0.5;\n" "}\n"; - const std::string fs = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform sampler2D tex;\n" @@ -1243,7 +1243,7 @@ TEST_P(CopyTextureTestES3, ES3UnormFormats) " color = texture(tex, texcoord);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLRenderbuffer rbo; @@ -1361,7 +1361,7 @@ TEST_P(CopyTextureTestES3, ES3FloatFormats) ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_color_buffer_float")); auto testOutput = [this](GLuint texture, const GLColor32F &expectedColor) { - const std::string vs = + constexpr char kVS[] = "#version 300 es\n" "in vec4 position;\n" "out vec2 texcoord;\n" @@ -1371,7 +1371,7 @@ TEST_P(CopyTextureTestES3, ES3FloatFormats) " texcoord = (position.xy * 0.5) + 0.5;\n" "}\n"; - const std::string fs = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform sampler2D tex;\n" @@ -1382,7 +1382,7 @@ TEST_P(CopyTextureTestES3, ES3FloatFormats) " color = texture(tex, texcoord);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLRenderbuffer rbo; @@ -1484,7 +1484,7 @@ TEST_P(CopyTextureTestES3, ES3UintFormats) using GLColor32U = std::tuple; auto testOutput = [this](GLuint texture, const GLColor32U &expectedColor) { - const std::string vs = + constexpr char kVS[] = "#version 300 es\n" "in vec4 position;\n" "out vec2 texcoord;\n" @@ -1494,7 +1494,7 @@ TEST_P(CopyTextureTestES3, ES3UintFormats) " texcoord = (position.xy * 0.5) + 0.5;\n" "}\n"; - std::string fs = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "precision mediump usampler2D;\n" @@ -1506,7 +1506,7 @@ TEST_P(CopyTextureTestES3, ES3UintFormats) " color = texture(tex, texcoord);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLRenderbuffer rbo; diff --git a/src/tests/gl_tests/D3D11InputLayoutCacheTest.cpp b/src/tests/gl_tests/D3D11InputLayoutCacheTest.cpp index 9c3e5e46b..3db474076 100644 --- a/src/tests/gl_tests/D3D11InputLayoutCacheTest.cpp +++ b/src/tests/gl_tests/D3D11InputLayoutCacheTest.cpp @@ -49,13 +49,13 @@ class D3D11InputLayoutCacheTest : public ANGLETest } strstr << " gl_Position = vec4(position, 0.0, 1.0);" << std::endl << "}" << std::endl; - const std::string basicFragmentShader = + constexpr char kFS[] = "varying highp float v;\n" "void main() {" " gl_FragColor = vec4(v / 255.0, 0.0, 0.0, 1.0);\n" "}\n"; - return CompileProgram(strstr.str(), basicFragmentShader); + return CompileProgram(strstr.str().c_str(), kFS); } }; diff --git a/src/tests/gl_tests/D3DImageFormatConversionTest.cpp b/src/tests/gl_tests/D3DImageFormatConversionTest.cpp index 3ac870b99..2866694e0 100644 --- a/src/tests/gl_tests/D3DImageFormatConversionTest.cpp +++ b/src/tests/gl_tests/D3DImageFormatConversionTest.cpp @@ -32,28 +32,26 @@ class D3DImageFormatConversionTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vertexShaderSource = - R"(precision highp float; - attribute vec4 position; - varying vec2 texcoord; + constexpr char kVS[] = R"(precision highp float; +attribute vec4 position; +varying vec2 texcoord; - void main() - { - gl_Position = vec4(position.xy, 0.0, 1.0); - texcoord = (position.xy * 0.5) + 0.5; - })"; +void main() +{ + gl_Position = vec4(position.xy, 0.0, 1.0); + texcoord = (position.xy * 0.5) + 0.5; +})"; - const std::string fragmentShaderSource2D = - R"(precision highp float; - uniform sampler2D tex; - varying vec2 texcoord; + constexpr char kFS[] = R"(precision highp float; +uniform sampler2D tex; +varying vec2 texcoord; - void main() - { - gl_FragColor = texture2D(tex, texcoord); - })"; +void main() +{ + gl_FragColor = texture2D(tex, texcoord); +})"; - m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D); + m2DProgram = CompileProgram(kVS, kFS); mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex"); } diff --git a/src/tests/gl_tests/D3DTextureTest.cpp b/src/tests/gl_tests/D3DTextureTest.cpp index 59014894a..b91ddc630 100644 --- a/src/tests/gl_tests/D3DTextureTest.cpp +++ b/src/tests/gl_tests/D3DTextureTest.cpp @@ -36,7 +36,7 @@ class D3DTextureTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vsSource = + constexpr char kVS[] = R"(precision highp float; attribute vec4 position; varying vec2 texcoord; @@ -48,7 +48,7 @@ class D3DTextureTest : public ANGLETest texcoord.y = 1.0 - texcoord.y; })"; - const std::string textureFSSource = + constexpr char kTextureFS[] = R"(precision highp float; uniform sampler2D tex; varying vec2 texcoord; @@ -58,7 +58,7 @@ class D3DTextureTest : public ANGLETest gl_FragColor = texture2D(tex, texcoord); })"; - const std::string textureFSSourceNoSampling = + constexpr char kTextureFSNoSampling[] = R"(precision highp float; void main() @@ -66,13 +66,13 @@ class D3DTextureTest : public ANGLETest gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0); })"; - mTextureProgram = CompileProgram(vsSource, textureFSSource); + mTextureProgram = CompileProgram(kVS, kTextureFS); ASSERT_NE(0u, mTextureProgram) << "shader compilation failed."; mTextureUniformLocation = glGetUniformLocation(mTextureProgram, "tex"); ASSERT_NE(-1, mTextureUniformLocation); - mTextureProgramNoSampling = CompileProgram(vsSource, textureFSSourceNoSampling); + mTextureProgramNoSampling = CompileProgram(kVS, kTextureFSNoSampling); ASSERT_NE(0u, mTextureProgramNoSampling) << "shader compilation failed."; mD3D11Module = LoadLibrary(TEXT("d3d11.dll")); diff --git a/src/tests/gl_tests/DXT1CompressedTextureTest.cpp b/src/tests/gl_tests/DXT1CompressedTextureTest.cpp index 42bf6651d..1cf62313a 100644 --- a/src/tests/gl_tests/DXT1CompressedTextureTest.cpp +++ b/src/tests/gl_tests/DXT1CompressedTextureTest.cpp @@ -28,29 +28,27 @@ class DXT1CompressedTextureTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vsSource = - R"(precision highp float; - attribute vec4 position; - varying vec2 texcoord; + constexpr char kVS[] = R"(precision highp float; +attribute vec4 position; +varying vec2 texcoord; - void main() - { - gl_Position = position; - texcoord = (position.xy * 0.5) + 0.5; - texcoord.y = 1.0 - texcoord.y; - })"; +void main() +{ + gl_Position = position; + texcoord = (position.xy * 0.5) + 0.5; + texcoord.y = 1.0 - texcoord.y; +})"; - const std::string textureFSSource = - R"(precision highp float; - uniform sampler2D tex; - varying vec2 texcoord; + constexpr char kFS[] = R"(precision highp float; +uniform sampler2D tex; +varying vec2 texcoord; - void main() - { - gl_FragColor = texture2D(tex, texcoord); - })"; +void main() +{ + gl_FragColor = texture2D(tex, texcoord); +})"; - mTextureProgram = CompileProgram(vsSource, textureFSSource); + mTextureProgram = CompileProgram(kVS, kFS); if (mTextureProgram == 0) { FAIL() << "shader compilation failed."; diff --git a/src/tests/gl_tests/DXTSRGBCompressedTextureTest.cpp b/src/tests/gl_tests/DXTSRGBCompressedTextureTest.cpp index f7aeb7692..c48ae0fc9 100644 --- a/src/tests/gl_tests/DXTSRGBCompressedTextureTest.cpp +++ b/src/tests/gl_tests/DXTSRGBCompressedTextureTest.cpp @@ -35,7 +35,7 @@ class DXTSRGBCompressedTextureTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vsSource = std::string( + constexpr char kVS[] = "precision highp float;\n" "attribute vec4 position;\n" "varying vec2 texcoord;\n" @@ -43,17 +43,17 @@ class DXTSRGBCompressedTextureTest : public ANGLETest " gl_Position = position;\n" " texcoord = (position.xy * 0.5) + 0.5;\n" " texcoord.y = 1.0 - texcoord.y;\n" - "}"); + "}"; - const std::string textureFSSource = std::string( + constexpr char kFS[] = "precision highp float;\n" "uniform sampler2D tex;\n" "varying vec2 texcoord;\n" "void main() {\n" " gl_FragColor = texture2D(tex, texcoord);\n" - "}\n"); + "}\n"; - mTextureProgram = CompileProgram(vsSource, textureFSSource); + mTextureProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mTextureProgram); mTextureUniformLocation = glGetUniformLocation(mTextureProgram, "tex"); diff --git a/src/tests/gl_tests/DepthStencilFormatsTest.cpp b/src/tests/gl_tests/DepthStencilFormatsTest.cpp index 56cb57bad..893369edc 100644 --- a/src/tests/gl_tests/DepthStencilFormatsTest.cpp +++ b/src/tests/gl_tests/DepthStencilFormatsTest.cpp @@ -68,28 +68,26 @@ class DepthStencilFormatsTestBase : public ANGLETest { ANGLETest::SetUp(); - const std::string vertexShaderSource = - R"(precision highp float; - attribute vec4 position; - varying vec2 texcoord; + constexpr char kVS[] = R"(precision highp float; +attribute vec4 position; +varying vec2 texcoord; - void main() - { - gl_Position = position; - texcoord = (position.xy * 0.5) + 0.5; - })"; +void main() +{ + gl_Position = position; + texcoord = (position.xy * 0.5) + 0.5; +})"; - const std::string fragmentShaderSource = - R"(precision highp float; - uniform sampler2D tex; - varying vec2 texcoord; + constexpr char kFS[] = R"(precision highp float; +uniform sampler2D tex; +varying vec2 texcoord; - void main() - { - gl_FragColor = texture2D(tex, texcoord); - })"; +void main() +{ + gl_FragColor = texture2D(tex, texcoord); +})"; - mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); if (mProgram == 0) { FAIL() << "shader compilation failed."; @@ -279,16 +277,16 @@ class TinyDepthStencilWorkaroundTest : public ANGLETest // http://anglebug.com/1664 TEST_P(TinyDepthStencilWorkaroundTest, DepthTexturesStick) { - const std::string &drawVS = + constexpr char kDrawVS[] = "#version 100\n" "attribute vec3 vertex;\n" "void main () {\n" " gl_Position = vec4(vertex.x, vertex.y, vertex.z * 2.0 - 1.0, 1);\n" "}\n"; - ANGLE_GL_PROGRAM(drawProgram, drawVS, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(drawProgram, kDrawVS, essl1_shaders::fs::Red()); - const std::string &blitVS = + constexpr char kBlitVS[] = "#version 100\n" "attribute vec2 vertex;\n" "varying vec2 position;\n" @@ -297,7 +295,7 @@ TEST_P(TinyDepthStencilWorkaroundTest, DepthTexturesStick) " gl_Position = vec4(vertex, 0, 1);\n" "}\n"; - const std::string &blitFS = + constexpr char kBlitFS[] = "#version 100\n" "precision mediump float;\n" "uniform sampler2D texture;\n" @@ -306,7 +304,7 @@ TEST_P(TinyDepthStencilWorkaroundTest, DepthTexturesStick) " gl_FragColor = vec4 (texture2D (texture, position).rrr, 1.);\n" "}\n"; - ANGLE_GL_PROGRAM(blitProgram, blitVS, blitFS); + ANGLE_GL_PROGRAM(blitProgram, kBlitVS, kBlitFS); GLint blitTextureLocation = glGetUniformLocation(blitProgram.get(), "texture"); ASSERT_NE(-1, blitTextureLocation); diff --git a/src/tests/gl_tests/DrawBuffersTest.cpp b/src/tests/gl_tests/DrawBuffersTest.cpp index 6018bb199..4870c6412 100644 --- a/src/tests/gl_tests/DrawBuffersTest.cpp +++ b/src/tests/gl_tests/DrawBuffersTest.cpp @@ -115,7 +115,7 @@ class DrawBuffersTest : public ANGLETest strstr << "}\n"; - *programOut = CompileProgram(essl3_shaders::vs::Simple(), strstr.str()); + *programOut = CompileProgram(essl3_shaders::vs::Simple(), strstr.str().c_str()); if (*programOut == 0) { FAIL() << "shader compilation failed."; @@ -146,7 +146,7 @@ class DrawBuffersTest : public ANGLETest strstr << "}\n"; - *programOut = CompileProgram(essl1_shaders::vs::Simple(), strstr.str()); + *programOut = CompileProgram(essl1_shaders::vs::Simple(), strstr.str().c_str()); if (*programOut == 0) { FAIL() << "shader compilation failed."; @@ -533,7 +533,7 @@ TEST_P(DrawBuffersTest, BroadcastGLFragColor) const GLenum bufs[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; - const std::string fragmentShaderSource = + constexpr char kFS[] = "#extension GL_EXT_draw_buffers : enable\n" "precision highp float;\n" "uniform float u_zero;\n" @@ -546,7 +546,7 @@ TEST_P(DrawBuffersTest, BroadcastGLFragColor) " }\n" "}\n"; - GLuint program = CompileProgram(essl1_shaders::vs::Simple(), fragmentShaderSource); + GLuint program = CompileProgram(essl1_shaders::vs::Simple(), kFS); if (program == 0) { FAIL() << "shader compilation failed."; diff --git a/src/tests/gl_tests/DrawElementsTest.cpp b/src/tests/gl_tests/DrawElementsTest.cpp index 344cb9982..9a401e593 100644 --- a/src/tests/gl_tests/DrawElementsTest.cpp +++ b/src/tests/gl_tests/DrawElementsTest.cpp @@ -73,14 +73,14 @@ class WebGLDrawElementsTest : public DrawElementsTest // Test no error is generated when using client-side arrays, indices = nullptr and count = 0 TEST_P(DrawElementsTest, ClientSideNullptrArrayZeroCount) { - const std::string &vert = + constexpr char kVS[] = "attribute vec3 a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Blue()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Blue()); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); ASSERT_NE(-1, posLocation); @@ -112,7 +112,7 @@ TEST_P(DrawElementsTest, ClientSideNullptrArrayZeroCount) TEST_P(DrawElementsTest, DeletingAfterStreamingIndexes) { // Init program - const std::string &vertexShader = + constexpr char kVS[] = "attribute vec2 position;\n" "attribute vec2 testFlag;\n" "varying vec2 v_data;\n" @@ -121,13 +121,13 @@ TEST_P(DrawElementsTest, DeletingAfterStreamingIndexes) " v_data = testFlag;\n" "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "varying highp vec2 v_data;\n" "void main() {\n" " gl_FragColor = vec4(v_data, 0, 1);\n" "}"; - mProgram = CompileProgram(vertexShader, fragmentShader); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); glUseProgram(mProgram); @@ -268,14 +268,14 @@ TEST_P(DrawElementsTest, DeletingAfterStreamingIndexes) // Test that the offset in the index buffer is forced to be a multiple of the element size TEST_P(WebGLDrawElementsTest, DrawElementsTypeAlignment) { - const std::string &vert = + constexpr char kVS[] = "attribute vec3 a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Blue()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Blue()); GLint posLocation = glGetAttribLocation(program, "a_pos"); ASSERT_NE(-1, posLocation); diff --git a/src/tests/gl_tests/FloatingPointSurfaceTest.cpp b/src/tests/gl_tests/FloatingPointSurfaceTest.cpp index 05e8984b7..c8d12ee9e 100644 --- a/src/tests/gl_tests/FloatingPointSurfaceTest.cpp +++ b/src/tests/gl_tests/FloatingPointSurfaceTest.cpp @@ -28,14 +28,14 @@ class FloatingPointSurfaceTest : public ANGLETest { ANGLETest::SetUp(); - const std::string fsSource = + constexpr char kFS[] = "precision highp float;\n" "void main()\n" "{\n" " gl_FragColor = vec4(1.0, 2.0, 3.0, 4.0);\n" "}\n"; - mProgram = CompileProgram(essl1_shaders::vs::Simple(), fsSource); + mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS); ASSERT_NE(0u, mProgram) << "shader compilation failed."; ASSERT_GL_NO_ERROR(); diff --git a/src/tests/gl_tests/FramebufferMultiviewTest.cpp b/src/tests/gl_tests/FramebufferMultiviewTest.cpp index 6acc3501f..6108ad13d 100644 --- a/src/tests/gl_tests/FramebufferMultiviewTest.cpp +++ b/src/tests/gl_tests/FramebufferMultiviewTest.cpp @@ -977,13 +977,13 @@ TEST_P(FramebufferMultiviewSideBySideClearTest, DepthBufferClear) ANGLE_SKIP_TEST_IF(!requestMultiviewExtension()); // Create program to draw a quad. - const std::string &vs = + constexpr char kVS[] = "#version 300 es\n" "in vec3 vPos;\n" "void main(){\n" " gl_Position = vec4(vPos, 1.);\n" "}\n"; - const std::string &fs = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform vec3 uCol;\n" @@ -991,7 +991,7 @@ TEST_P(FramebufferMultiviewSideBySideClearTest, DepthBufferClear) "void main(){\n" " col = vec4(uCol,1.);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLuint mColorUniformLoc = glGetUniformLocation(program, "uCol"); @@ -1030,13 +1030,13 @@ TEST_P(FramebufferMultiviewSideBySideClearTest, StencilBufferClear) ANGLE_SKIP_TEST_IF(!requestMultiviewExtension()); // Create program to draw a quad. - const std::string &vs = + constexpr char kVS[] = "#version 300 es\n" "in vec3 vPos;\n" "void main(){\n" " gl_Position = vec4(vPos, 1.);\n" "}\n"; - const std::string &fs = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform vec3 uCol;\n" @@ -1044,7 +1044,7 @@ TEST_P(FramebufferMultiviewSideBySideClearTest, StencilBufferClear) "void main(){\n" " col = vec4(uCol,1.);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLuint mColorUniformLoc = glGetUniformLocation(program, "uCol"); @@ -1185,13 +1185,13 @@ TEST_P(FramebufferMultiviewLayeredClearTest, ClearBufferfi) ANGLE_SKIP_TEST_IF(!requestMultiviewExtension()); // Create program to draw a quad. - const std::string &vs = + constexpr char kVS[] = "#version 300 es\n" "in vec3 vPos;\n" "void main(){\n" " gl_Position = vec4(vPos, 1.);\n" "}\n"; - const std::string &fs = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform vec3 uCol;\n" @@ -1199,7 +1199,7 @@ TEST_P(FramebufferMultiviewLayeredClearTest, ClearBufferfi) "void main(){\n" " col = vec4(uCol,1.);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLuint mColorUniformLoc = glGetUniformLocation(program, "uCol"); @@ -1313,13 +1313,13 @@ TEST_P(FramebufferMultiviewLayeredClearTest, ScissoredClearBufferfi) ANGLE_SKIP_TEST_IF(!requestMultiviewExtension()); // Create program to draw a quad. - const std::string &vs = + constexpr char kVS[] = "#version 300 es\n" "in vec3 vPos;\n" "void main(){\n" " gl_Position = vec4(vPos, 1.);\n" "}\n"; - const std::string &fs = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform vec3 uCol;\n" @@ -1327,7 +1327,7 @@ TEST_P(FramebufferMultiviewLayeredClearTest, ScissoredClearBufferfi) "void main(){\n" " col = vec4(uCol,1.);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLuint mColorUniformLoc = glGetUniformLocation(program, "uCol"); diff --git a/src/tests/gl_tests/FramebufferTest.cpp b/src/tests/gl_tests/FramebufferTest.cpp index 69ffbc4ff..5100fe597 100644 --- a/src/tests/gl_tests/FramebufferTest.cpp +++ b/src/tests/gl_tests/FramebufferTest.cpp @@ -800,46 +800,42 @@ TEST_P(FramebufferTest_ES31, RenderingLimitToDefaultFBOSizeWithNoAttachments) // anglebug.com/2253 ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL()); - const std::string &vertexShader1 = - R"(#version 310 es - in layout(location = 0) highp vec2 a_position; - void main() - { - gl_Position = vec4(a_position, 0.0, 1.0); - })"; + constexpr char kVS1[] = R"(#version 310 es +in layout(location = 0) highp vec2 a_position; +void main() +{ + gl_Position = vec4(a_position, 0.0, 1.0); +})"; - const std::string &fragShader1 = - R"(#version 310 es - uniform layout(location = 0) highp ivec2 u_expectedSize; - out layout(location = 5) mediump vec4 f_color; - void main() - { - if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; - f_color = vec4(1.0, 0.5, 0.25, 1.0); - })"; + constexpr char kFS1[] = R"(#version 310 es +uniform layout(location = 0) highp ivec2 u_expectedSize; +out layout(location = 5) mediump vec4 f_color; +void main() +{ + if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; + f_color = vec4(1.0, 0.5, 0.25, 1.0); +})"; - const std::string &vertexShader2 = - R"(#version 310 es - in layout(location = 0) highp vec2 a_position; - void main() - { - gl_Position = vec4(a_position, 0.0, 1.0); - })"; + constexpr char kVS2[] = R"(#version 310 es +in layout(location = 0) highp vec2 a_position; +void main() +{ + gl_Position = vec4(a_position, 0.0, 1.0); +})"; - const std::string &fragShader2 = - R"(#version 310 es - uniform layout(location = 0) highp ivec2 u_expectedSize; - out layout(location = 2) mediump vec4 f_color; - void main() - { - if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; - f_color = vec4(1.0, 0.5, 0.25, 1.0); - })"; + constexpr char kFS2[] = R"(#version 310 es +uniform layout(location = 0) highp ivec2 u_expectedSize; +out layout(location = 2) mediump vec4 f_color; +void main() +{ + if (ivec2(gl_FragCoord.xy) != u_expectedSize) discard; + f_color = vec4(1.0, 0.5, 0.25, 1.0); +})"; - GLuint program1 = CompileProgram(vertexShader1, fragShader1); + GLuint program1 = CompileProgram(kVS1, kFS1); ASSERT_NE(program1, 0u); - GLuint program2 = CompileProgram(vertexShader2, fragShader2); + GLuint program2 = CompileProgram(kVS2, kFS2); ASSERT_NE(program2, 0u); glUseProgram(program1); @@ -936,10 +932,10 @@ class AddDummyTextureNoRenderTargetTest : public ANGLETest // Test to verify workaround succeeds when no program outputs exist http://anglebug.com/2283 TEST_P(AddDummyTextureNoRenderTargetTest, NoProgramOutputWorkaround) { - const std::string &vShader = "void main() {}"; - const std::string &fShader = "void main() {}"; + constexpr char kVS[] = "void main() {}"; + constexpr char kFS[] = "void main() {}"; - ANGLE_GL_PROGRAM(drawProgram, vShader, fShader); + ANGLE_GL_PROGRAM(drawProgram, kVS, kFS); glUseProgram(drawProgram); diff --git a/src/tests/gl_tests/GLSLTest.cpp b/src/tests/gl_tests/GLSLTest.cpp index 4741a65d0..38589c82c 100644 --- a/src/tests/gl_tests/GLSLTest.cpp +++ b/src/tests/gl_tests/GLSLTest.cpp @@ -348,7 +348,7 @@ class GLSLTest : public ANGLETest usePointCoord, usePointSize, &fragmentShaderSource, &vertexShaderSource); - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str()); if (expectSuccess) { @@ -433,7 +433,7 @@ class GLSLTest : public ANGLETest fragmentShader << "}\n"; - GLuint program = CompileProgram(vertexShader.str(), fragmentShader.str()); + GLuint program = CompileProgram(vertexShader.str().c_str(), fragmentShader.str().c_str()); if (expectSuccess) { @@ -463,10 +463,10 @@ class GLSLTest : public ANGLETest return ""; } - void validateComponentsInErrorMessage(const std::string &vertexShader, - const std::string &fragmentShader, - const std::string &expectedErrorType, - const std::string &expectedVariableFullName) + void validateComponentsInErrorMessage(const char *vertexShader, + const char *fragmentShader, + const char *expectedErrorType, + const char *expectedVariableFullName) { GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader); GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader); @@ -510,21 +510,19 @@ class GLSLTest_ES31 : public GLSLTest TEST_P(GLSLTest, NamelessScopedStructs) { - const std::string fragmentShaderSource = - R"(precision mediump float; - void main() - { - struct - { - float q; - } b; + constexpr char kFS[] = R"(precision mediump float; +void main() +{ + struct + { + float q; + } b; - gl_FragColor = vec4(1, 0, 0, 1); - gl_FragColor.a += b.q; - })"; + gl_FragColor = vec4(1, 0, 0, 1); + gl_FragColor.a += b.q; +})"; - GLuint program = CompileProgram(essl1_shaders::vs::Simple(), fragmentShaderSource); - EXPECT_NE(0u, program); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); } TEST_P(GLSLTest, ScopedStructsOrderBug) @@ -535,92 +533,85 @@ TEST_P(GLSLTest, ScopedStructsOrderBug) // (http://anglebug.com/1291) ANGLE_SKIP_TEST_IF(IsDesktopOpenGL() && (IsOSX() || !IsNVIDIA())); - const std::string fragmentShaderSource = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; - struct T - { - float f; - }; +struct T +{ + float f; +}; - void main() - { - T a; +void main() +{ + T a; - struct T - { - float q; - }; + struct T + { + float q; + }; - T b; + T b; - gl_FragColor = vec4(1, 0, 0, 1); - gl_FragColor.a += a.f; - gl_FragColor.a += b.q; - })"; + gl_FragColor = vec4(1, 0, 0, 1); + gl_FragColor.a += a.f; + gl_FragColor.a += b.q; +})"; - GLuint program = CompileProgram(essl1_shaders::vs::Simple(), fragmentShaderSource); - EXPECT_NE(0u, program); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); } TEST_P(GLSLTest, ScopedStructsBug) { - const std::string fragmentShaderSource = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; - struct T_0 - { - float f; - }; +struct T_0 +{ + float f; +}; - void main() - { - gl_FragColor = vec4(1, 0, 0, 1); +void main() +{ + gl_FragColor = vec4(1, 0, 0, 1); - struct T - { - vec2 v; - }; + struct T + { + vec2 v; + }; - T_0 a; - T b; + T_0 a; + T b; - gl_FragColor.a += a.f; - gl_FragColor.a += b.v.x; - })"; + gl_FragColor.a += a.f; + gl_FragColor.a += b.v.x; +})"; - GLuint program = CompileProgram(essl1_shaders::vs::Simple(), fragmentShaderSource); - EXPECT_NE(0u, program); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); } TEST_P(GLSLTest, DxPositionBug) { - const std::string &vertexShaderSource = - R"(attribute vec4 inputAttribute; - varying float dx_Position; - void main() - { - gl_Position = vec4(inputAttribute); - dx_Position = 0.0; - })"; + constexpr char kVS[] = R"(attribute vec4 inputAttribute; +varying float dx_Position; +void main() +{ + gl_Position = vec4(inputAttribute); + dx_Position = 0.0; +})"; - const std::string &fragmentShaderSource = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; - varying float dx_Position; +varying float dx_Position; - void main() - { - gl_FragColor = vec4(dx_Position, 0, 0, 1); - })"; +void main() +{ + gl_FragColor = vec4(dx_Position, 0, 0, 1); +})"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); - EXPECT_NE(0u, program); + ANGLE_GL_PROGRAM(program, kVS, kFS); } TEST_P(GLSLTest, ElseIfRewriting) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "attribute vec4 a_position;\n" "varying float v;\n" "void main() {\n" @@ -633,7 +624,7 @@ TEST_P(GLSLTest, ElseIfRewriting) " }\n" "}\n"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "precision highp float;\n" "varying float v;\n" "void main() {\n" @@ -643,8 +634,7 @@ TEST_P(GLSLTest, ElseIfRewriting) " gl_FragColor = color;\n" "}\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); - ASSERT_NE(0u, program); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "a_position", 0.5f); @@ -654,7 +644,7 @@ TEST_P(GLSLTest, ElseIfRewriting) TEST_P(GLSLTest, TwoElseIfRewriting) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "attribute vec4 a_position;\n" "varying float v;\n" "void main() {\n" @@ -668,49 +658,46 @@ TEST_P(GLSLTest, TwoElseIfRewriting) " }\n" "}\n"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "precision highp float;\n" "varying float v;\n" "void main() {\n" " gl_FragColor = vec4(v, 0.0, 0.0, 1.0);\n" "}\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); - EXPECT_NE(0u, program); + ANGLE_GL_PROGRAM(program, kVS, kFS); } TEST_P(GLSLTest, FrontFacingAndVarying) { EGLPlatformParameters platform = GetParam().eglParameters; - const std::string vertexShaderSource = - R"(attribute vec4 a_position; - varying float v_varying; - void main() - { - v_varying = a_position.x; - gl_Position = a_position; - })"; + constexpr char kVS[] = R"(attribute vec4 a_position; +varying float v_varying; +void main() +{ + v_varying = a_position.x; + gl_Position = a_position; +})"; - const std::string fragmentShaderSource = - R"(precision mediump float; - varying float v_varying; - void main() - { - vec4 c; + constexpr char kFS[] = R"(precision mediump float; +varying float v_varying; +void main() +{ + vec4 c; - if (gl_FrontFacing) - { - c = vec4(v_varying, 0, 0, 1.0); - } - else - { - c = vec4(0, v_varying, 0, 1.0); - } - gl_FragColor = c; - })"; + if (gl_FrontFacing) + { + c = vec4(v_varying, 0, 0, 1.0); + } + else + { + c = vec4(0, v_varying, 0, 1.0); + } + gl_FragColor = c; +})"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); // Compilation should fail on D3D11 feature level 9_3, since gl_FrontFacing isn't supported. if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE) @@ -762,17 +749,17 @@ TEST_P(GLSLTest_ES3, VersionMismatch) // Verify that declaring varying as invariant only in vertex shader fails in ESSL 1.00. TEST_P(GLSLTest, InvariantVaryingOut) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "precision mediump float;\n" "varying float v_varying;\n" "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "attribute vec4 a_position;\n" "invariant varying float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } @@ -783,133 +770,133 @@ TEST_P(GLSLTest_ES3, InvariantVaryingOut) // for varyings which are invariant in vertex shader (http://anglebug.com/1293) ANGLE_SKIP_TEST_IF(IsDesktopOpenGL()); - const std::string fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "in float v_varying;\n" "out vec4 my_FragColor;\n" "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec4 a_position;\n" "invariant out float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_NE(0u, program); } // Verify that declaring varying as invariant only in fragment shader fails in ESSL 1.00. TEST_P(GLSLTest, InvariantVaryingIn) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "precision mediump float;\n" "invariant varying float v_varying;\n" "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "attribute vec4 a_position;\n" "varying float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } // Verify that declaring varying as invariant only in fragment shader fails in ESSL 3.00. TEST_P(GLSLTest_ES3, InvariantVaryingIn) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "invariant in float v_varying;\n" "out vec4 my_FragColor;\n" "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec4 a_position;\n" "out float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } // Verify that declaring varying as invariant in both shaders succeeds in ESSL 1.00. TEST_P(GLSLTest, InvariantVaryingBoth) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "precision mediump float;\n" "invariant varying float v_varying;\n" "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "attribute vec4 a_position;\n" "invariant varying float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_NE(0u, program); } // Verify that declaring varying as invariant in both shaders fails in ESSL 3.00. TEST_P(GLSLTest_ES3, InvariantVaryingBoth) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "invariant in float v_varying;\n" "out vec4 my_FragColor;\n" "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec4 a_position;\n" "invariant out float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } // Verify that declaring gl_Position as invariant succeeds in ESSL 1.00. TEST_P(GLSLTest, InvariantGLPosition) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "precision mediump float;\n" "varying float v_varying;\n" "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "attribute vec4 a_position;\n" "invariant gl_Position;\n" "varying float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_NE(0u, program); } // Verify that declaring gl_Position as invariant succeeds in ESSL 3.00. TEST_P(GLSLTest_ES3, InvariantGLPosition) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "in float v_varying;\n" "out vec4 my_FragColor;\n" "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec4 a_position;\n" "invariant gl_Position;\n" "out float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_NE(0u, program); } @@ -921,124 +908,124 @@ TEST_P(GLSLTest, InvariantAllBoth) // and remove invariant(all) from fragment shader (http://anglebug.com/1293) ANGLE_SKIP_TEST_IF(IsDesktopOpenGL()); - const std::string fragmentShaderSource = + constexpr char kFS[] = "#pragma STDGL invariant(all)\n" "precision mediump float;\n" "varying float v_varying;\n" "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "#pragma STDGL invariant(all)\n" "attribute vec4 a_position;\n" "varying float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_NE(0u, program); } // Verify that functions without return statements still compile TEST_P(GLSLTest, MissingReturnFloat) { - const std::string vertexShaderSource = + constexpr char kVS[] = "varying float v_varying;\n" "float f() { if (v_varying > 0.0) return 1.0; }\n" "void main() { gl_Position = vec4(f(), 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl1_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl1_shaders::fs::Red()); EXPECT_NE(0u, program); } // Verify that functions without return statements still compile TEST_P(GLSLTest, MissingReturnVec2) { - const std::string vertexShaderSource = + constexpr char kVS[] = "varying float v_varying;\n" "vec2 f() { if (v_varying > 0.0) return vec2(1.0, 1.0); }\n" "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl1_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl1_shaders::fs::Red()); EXPECT_NE(0u, program); } // Verify that functions without return statements still compile TEST_P(GLSLTest, MissingReturnVec3) { - const std::string vertexShaderSource = + constexpr char kVS[] = "varying float v_varying;\n" "vec3 f() { if (v_varying > 0.0) return vec3(1.0, 1.0, 1.0); }\n" "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl1_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl1_shaders::fs::Red()); EXPECT_NE(0u, program); } // Verify that functions without return statements still compile TEST_P(GLSLTest, MissingReturnVec4) { - const std::string vertexShaderSource = + constexpr char kVS[] = "varying float v_varying;\n" "vec4 f() { if (v_varying > 0.0) return vec4(1.0, 1.0, 1.0, 1.0); }\n" "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl1_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl1_shaders::fs::Red()); EXPECT_NE(0u, program); } // Verify that functions without return statements still compile TEST_P(GLSLTest, MissingReturnIVec4) { - const std::string vertexShaderSource = + constexpr char kVS[] = "varying float v_varying;\n" "ivec4 f() { if (v_varying > 0.0) return ivec4(1, 1, 1, 1); }\n" "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl1_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl1_shaders::fs::Red()); EXPECT_NE(0u, program); } // Verify that functions without return statements still compile TEST_P(GLSLTest, MissingReturnMat4) { - const std::string vertexShaderSource = + constexpr char kVS[] = "varying float v_varying;\n" "mat4 f() { if (v_varying > 0.0) return mat4(1.0); }\n" "void main() { gl_Position = vec4(f()[0][0], 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl1_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl1_shaders::fs::Red()); EXPECT_NE(0u, program); } // Verify that functions without return statements still compile TEST_P(GLSLTest, MissingReturnStruct) { - const std::string vertexShaderSource = + constexpr char kVS[] = "varying float v_varying;\n" "struct s { float a; int b; vec2 c; };\n" "s f() { if (v_varying > 0.0) return s(1.0, 1, vec2(1.0, 1.0)); }\n" "void main() { gl_Position = vec4(f().a, 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl1_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl1_shaders::fs::Red()); EXPECT_NE(0u, program); } // Verify that functions without return statements still compile TEST_P(GLSLTest_ES3, MissingReturnArray) { - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in float v_varying;\n" "vec2[2] f() { if (v_varying > 0.0) { return vec2[2](vec2(1.0, 1.0), vec2(1.0, 1.0)); } }\n" "void main() { gl_Position = vec4(f()[0].x, 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl3_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl3_shaders::fs::Red()); EXPECT_NE(0u, program); } // Verify that functions without return statements still compile TEST_P(GLSLTest_ES3, MissingReturnArrayOfStructs) { - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in float v_varying;\n" "struct s { float a; int b; vec2 c; };\n" @@ -1046,7 +1033,7 @@ TEST_P(GLSLTest_ES3, MissingReturnArrayOfStructs) "vec2(1.0, 1.0))); } }\n" "void main() { gl_Position = vec4(f()[0].a, 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl3_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl3_shaders::fs::Red()); EXPECT_NE(0u, program); } @@ -1059,7 +1046,7 @@ TEST_P(GLSLTest_ES3, MissingReturnStructOfArrays) // It disallows returning structure of arrays on NVIDIA OpenGL ES. ANGLE_SKIP_TEST_IF(IsNVIDIA() && IsOpenGLES()); - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in float v_varying;\n" "struct s { float a[2]; int b[2]; vec2 c[2]; };\n" @@ -1067,14 +1054,14 @@ TEST_P(GLSLTest_ES3, MissingReturnStructOfArrays) "vec2[2](vec2(1.0, 1.0), vec2(1.0, 1.0))); } }\n" "void main() { gl_Position = vec4(f().a[0], 0, 0, 1); }\n"; - GLuint program = CompileProgram(vertexShaderSource, essl3_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl3_shaders::fs::Red()); EXPECT_NE(0u, program); } // Verify that using invariant(all) in both shaders fails in ESSL 3.00. TEST_P(GLSLTest_ES3, InvariantAllBoth) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "#pragma STDGL invariant(all)\n" "precision mediump float;\n" @@ -1082,39 +1069,39 @@ TEST_P(GLSLTest_ES3, InvariantAllBoth) "out vec4 my_FragColor;\n" "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "#pragma STDGL invariant(all)\n" "in vec4 a_position;\n" "out float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } // Verify that using invariant(all) only in fragment shader fails in ESSL 1.00. TEST_P(GLSLTest, InvariantAllIn) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "#pragma STDGL invariant(all)\n" "precision mediump float;\n" "varying float v_varying;\n" "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "attribute vec4 a_position;\n" "varying float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } // Verify that using invariant(all) only in fragment shader fails in ESSL 3.00. TEST_P(GLSLTest_ES3, InvariantAllIn) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "#pragma STDGL invariant(all)\n" "precision mediump float;\n" @@ -1122,31 +1109,31 @@ TEST_P(GLSLTest_ES3, InvariantAllIn) "out vec4 my_FragColor;\n" "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec4 a_position;\n" "out float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } // Verify that using invariant(all) only in vertex shader fails in ESSL 1.00. TEST_P(GLSLTest, InvariantAllOut) { - const std::string fragmentShaderSource = + constexpr char kFS[] = "precision mediump float;\n" "varying float v_varying;\n" "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "#pragma STDGL invariant(all)\n" "attribute vec4 a_position;\n" "varying float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } @@ -1158,21 +1145,21 @@ TEST_P(GLSLTest_ES3, InvariantAllOut) // because of invariant(all) being used in vertex shader (http://anglebug.com/1293) ANGLE_SKIP_TEST_IF(IsDesktopOpenGL()); - const std::string fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "in float v_varying;\n" "out vec4 my_FragColor;\n" "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n"; - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "#pragma STDGL invariant(all)\n" "in vec4 a_position;\n" "out float v_varying;\n" "void main() { v_varying = a_position.x; gl_Position = a_position; }\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_NE(0u, program); } @@ -1417,7 +1404,7 @@ TEST_P(GLSLTest, ZeroShaderLength) // https://code.google.com/p/angleproject/issues/detail?id=857 TEST_P(GLSLTest, BadIndexBug) { - const std::string &fragmentShaderSourceVec = + constexpr char kFSSourceVec[] = "precision mediump float;\n" "uniform vec4 uniformVec;\n" "void main()\n" @@ -1425,7 +1412,7 @@ TEST_P(GLSLTest, BadIndexBug) " gl_FragColor = vec4(uniformVec[int()]);\n" "}"; - GLuint shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceVec); + GLuint shader = CompileShader(GL_FRAGMENT_SHADER, kFSSourceVec); EXPECT_EQ(0u, shader); if (shader != 0) @@ -1433,7 +1420,7 @@ TEST_P(GLSLTest, BadIndexBug) glDeleteShader(shader); } - const std::string &fragmentShaderSourceMat = + constexpr char kFSSourceMat[] = "precision mediump float;\n" "uniform mat4 uniformMat;\n" "void main()\n" @@ -1441,7 +1428,7 @@ TEST_P(GLSLTest, BadIndexBug) " gl_FragColor = vec4(uniformMat[int()]);\n" "}"; - shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceMat); + shader = CompileShader(GL_FRAGMENT_SHADER, kFSSourceMat); EXPECT_EQ(0u, shader); if (shader != 0) @@ -1449,7 +1436,7 @@ TEST_P(GLSLTest, BadIndexBug) glDeleteShader(shader); } - const std::string &fragmentShaderSourceArray = + constexpr char kFSSourceArray[] = "precision mediump float;\n" "uniform vec4 uniformArray;\n" "void main()\n" @@ -1457,7 +1444,7 @@ TEST_P(GLSLTest, BadIndexBug) " gl_FragColor = vec4(uniformArray[int()]);\n" "}"; - shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceArray); + shader = CompileShader(GL_FRAGMENT_SHADER, kFSSourceArray); EXPECT_EQ(0u, shader); if (shader != 0) @@ -1469,36 +1456,34 @@ TEST_P(GLSLTest, BadIndexBug) // Test that structs defined in uniforms are translated correctly. TEST_P(GLSLTest, StructSpecifiersUniforms) { - const std::string fragmentShaderSource = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; - uniform struct S { float field; } s; +uniform struct S { float field; } s; - void main() - { - gl_FragColor = vec4(1, 0, 0, 1); - gl_FragColor.a += s.field; - })"; +void main() +{ + gl_FragColor = vec4(1, 0, 0, 1); + gl_FragColor.a += s.field; +})"; - GLuint program = CompileProgram(essl1_shaders::vs::Simple(), fragmentShaderSource); + GLuint program = CompileProgram(essl1_shaders::vs::Simple(), kFS); EXPECT_NE(0u, program); } // Test that structs declaration followed directly by an initialization is translated correctly. TEST_P(GLSLTest, StructWithInitializer) { - const std::string fragmentShaderSource = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; - struct S { float a; } s = S(1.0); +struct S { float a; } s = S(1.0); - void main() - { - gl_FragColor = vec4(0, 0, 0, 1); - gl_FragColor.r += s.a; - })"; +void main() +{ + gl_FragColor = vec4(0, 0, 0, 1); + gl_FragColor.r += s.a; +})"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShaderSource); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); glUseProgram(program); // Test drawing, should be red. @@ -1511,18 +1496,17 @@ TEST_P(GLSLTest, StructWithInitializer) // Test that structs without initializer, followed by a uniform usage works as expected. TEST_P(GLSLTest, UniformStructWithoutInitializer) { - const std::string fragmentShaderSource = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; - struct S { float a; }; - uniform S u_s; +struct S { float a; }; +uniform S u_s; - void main() - { - gl_FragColor = vec4(u_s.a); - })"; +void main() +{ + gl_FragColor = vec4(u_s.a); +})"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShaderSource); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); glUseProgram(program); // Test drawing, should be red. @@ -1535,20 +1519,19 @@ TEST_P(GLSLTest, UniformStructWithoutInitializer) // Test that structs declaration followed directly by an initialization in a uniform. TEST_P(GLSLTest, StructWithUniformInitializer) { - const std::string fragmentShaderSource = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; - struct S { float a; } s = S(1.0); - uniform S us; +struct S { float a; } s = S(1.0); +uniform S us; - void main() - { - gl_FragColor = vec4(0, 0, 0, 1); - gl_FragColor.r += s.a; - gl_FragColor.g += us.a; - })"; +void main() +{ + gl_FragColor = vec4(0, 0, 0, 1); + gl_FragColor.r += s.a; + gl_FragColor.g += us.a; +})"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShaderSource); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); glUseProgram(program); // Test drawing, should be red. @@ -1564,15 +1547,14 @@ TEST_P(GLSLTest, StructWithUniformInitializer) // (note this test is still Impl-independent) TEST_P(GLSLTestNoValidation, DepthRangeUniforms) { - const std::string fragmentShaderSource = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; - void main() - { - gl_FragColor = vec4(gl_DepthRange.near, gl_DepthRange.far, gl_DepthRange.diff, 1); - })"; +void main() +{ + gl_FragColor = vec4(gl_DepthRange.near, gl_DepthRange.far, gl_DepthRange.diff, 1); +})"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShaderSource); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); // We need to bypass validation for this call. GLint nearIndex = glGetUniformLocation(program.get(), "gl_DepthRange.near"); @@ -1642,7 +1624,7 @@ TEST_P(GLSLTest, PowOfSmallConstant) { const std::string &fragmentShaderSource = GenerateSmallPowShader(1.0e-6, testExponent); - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShaderSource); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShaderSource.c_str()); drawQuad(program.get(), essl1_shaders::PositionAttrib(), 0.5f); @@ -1658,26 +1640,25 @@ TEST_P(GLSLTest, PowOfSmallConstant) // than FL9_3. TEST_P(GLSLTest, LoopIndexingValidation) { - const std::string fragmentShaderSource = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; - uniform float loopMax; +uniform float loopMax; - void main() +void main() +{ + gl_FragColor = vec4(1, 0, 0, 1); + for (float l = 0.0; l < loopMax; l++) + { + if (loopMax > 3.0) { - gl_FragColor = vec4(1, 0, 0, 1); - for (float l = 0.0; l < loopMax; l++) - { - if (loopMax > 3.0) - { - gl_FragColor.a += 0.1; - } - } - })"; + gl_FragColor.a += 0.1; + } + } +})"; GLuint shader = glCreateShader(GL_FRAGMENT_SHADER); - const char *sourceArray[1] = {fragmentShaderSource.c_str()}; + const char *sourceArray[1] = {kFS}; glShaderSource(shader, 1, sourceArray, nullptr); glCompileShader(shader); @@ -1813,7 +1794,7 @@ TEST_P(GLSLTest, TextureLOD) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_shader_texture_lod")); - const std::string source = + constexpr char kFS[] = "#extension GL_EXT_shader_texture_lod : require\n" "uniform sampler2D u_texture;\n" "void main() {\n" @@ -1821,7 +1802,7 @@ TEST_P(GLSLTest, TextureLOD) "0.0));\n" "}\n"; - GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); + GLuint shader = CompileShader(GL_FRAGMENT_SHADER, kFS); ASSERT_NE(0u, shader); glDeleteShader(shader); } @@ -1830,26 +1811,25 @@ TEST_P(GLSLTest, TextureLOD) // but used in the fragment shader. TEST_P(GLSLTest, VerifySamplerInBothVertexAndFragmentShaders) { - const std::string vs = R"( - attribute vec2 position; - varying mediump vec2 texCoord; - uniform sampler2D tex; - void main() - { - gl_Position = vec4(position, 0, 1); - texCoord = position * 0.5 + vec2(0.5); - })"; + constexpr char kVS[] = R"( +attribute vec2 position; +varying mediump vec2 texCoord; +uniform sampler2D tex; +void main() +{ + gl_Position = vec4(position, 0, 1); + texCoord = position * 0.5 + vec2(0.5); +})"; - const std::string fs = R"( - varying mediump vec2 texCoord; - uniform sampler2D tex; - void main() - { - gl_FragColor = texture2D(tex, texCoord); - })"; + constexpr char kFS[] = R"( +varying mediump vec2 texCoord; +uniform sampler2D tex; +void main() +{ + gl_FragColor = texture2D(tex, texCoord); +})"; - GLuint program = CompileProgram(vs, fs); - EXPECT_NE(0u, program); + ANGLE_GL_PROGRAM(program, kVS, kFS); // Initialize basic red texture. const std::vector redColors(4, GLColor::red); @@ -1869,7 +1849,7 @@ TEST_P(GLSLTest, VerifySamplerInBothVertexAndFragmentShaders) // HLSL). TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x2) { - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "precision highp float;\n" "in vec4 a_vec;\n" @@ -1879,7 +1859,7 @@ TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x2) " gl_Position = vec4(a_vec) + vec4(a_mat);\n" "}"; - GLuint program = CompileProgram(vertexShaderSource, essl3_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl3_shaders::fs::Red()); EXPECT_NE(0u, program); } @@ -1888,7 +1868,7 @@ TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x2) // the function signatures in this case. TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x3) { - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "precision highp float;\n" "in mat3x2 a_matA;\n" @@ -1898,14 +1878,14 @@ TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x3) " gl_Position = vec4(a_matA) + vec4(a_matB);\n" "}"; - GLuint program = CompileProgram(vertexShaderSource, essl3_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl3_shaders::fs::Red()); EXPECT_NE(0u, program); } // Test that two functions which have vec4 and mat2 parameters get disambiguated (issue in HLSL). TEST_P(GLSLTest_ES3, AmbiguousFunctionCall2x2) { - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "precision highp float;\n" "in vec4 a_vec;\n" @@ -1923,7 +1903,7 @@ TEST_P(GLSLTest_ES3, AmbiguousFunctionCall2x2) " gl_Position = foo(a_vec) + foo(a_mat);\n" "}"; - GLuint program = CompileProgram(vertexShaderSource, essl3_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl3_shaders::fs::Red()); EXPECT_NE(0u, program); } @@ -1961,7 +1941,7 @@ TEST_P(GLSLTest_ES3, LargeNumberOfFloat4Parameters) vertexShaderStream << "a_vec);\n" "}"; - GLuint program = CompileProgram(vertexShaderStream.str(), essl3_shaders::fs::Red()); + GLuint program = CompileProgram(vertexShaderStream.str().c_str(), essl3_shaders::fs::Red()); EXPECT_NE(0u, program); } @@ -1977,7 +1957,7 @@ TEST_P(GLSLTest_ES3, InitGlobalArrayWithArrayIndexing) // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1428 is fixed ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); - const std::string fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 my_FragColor;\n" @@ -1988,7 +1968,7 @@ TEST_P(GLSLTest_ES3, InitGlobalArrayWithArrayIndexing) " my_FragColor = vec4(h[1]);\n" "}"; - GLuint program = CompileProgram(essl3_shaders::vs::Simple(), fragmentShaderSource); + GLuint program = CompileProgram(essl3_shaders::vs::Simple(), kFS); EXPECT_NE(0u, program); } @@ -1997,7 +1977,7 @@ TEST_P(GLSLTest, IndexConstantSamplerArrayIndexing) { ANGLE_SKIP_TEST_IF(IsD3D11_FL93()); - const std::string fragmentShaderSource = + constexpr char kFS[] = "precision mediump float;\n" "uniform sampler2D uni[2];\n" "\n" @@ -2022,7 +2002,7 @@ TEST_P(GLSLTest, IndexConstantSamplerArrayIndexing) " gl_FragColor = c;\n" "}"; - GLuint program = CompileProgram(essl1_shaders::vs::Simple(), fragmentShaderSource); + GLuint program = CompileProgram(essl1_shaders::vs::Simple(), kFS); EXPECT_NE(0u, program); } @@ -2031,14 +2011,14 @@ TEST_P(GLSLTest, IndexConstantSamplerArrayIndexing) // want to test its behavior, so don't use any varyings. TEST_P(GLSLTest, PragmaDirective) { - const std::string vertexShaderSource = + constexpr char kVS[] = "#pragma STDGL invariant(all)\n" "void main()\n" "{\n" " gl_Position = vec4(1.0, 0.0, 0.0, 1.0);\n" "}\n"; - GLuint program = CompileProgram(vertexShaderSource, essl1_shaders::fs::Red()); + GLuint program = CompileProgram(kVS, essl1_shaders::fs::Red()); EXPECT_NE(0u, program); } @@ -2047,7 +2027,7 @@ TEST_P(GLSLTest, PragmaDirective) // return the correct value (true). TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderArray) { - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 my_FragColor; \n" @@ -2064,7 +2044,7 @@ TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderArray) " my_FragColor = vec4(0.0, (result ? 1.0 : 0.0), 0.0, 1.0);\n" "}\n"; - GLuint program = CompileProgram(essl3_shaders::vs::Simple(), fragmentShaderSource); + GLuint program = CompileProgram(essl3_shaders::vs::Simple(), kFS); ASSERT_NE(0u, program); drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f); @@ -2077,7 +2057,7 @@ TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderArray) // correct value (true). TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderShortCircuit) { - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 my_FragColor; \n" @@ -2087,7 +2067,7 @@ TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderShortCircuit) " my_FragColor = vec4(0.0, ((result && j == 1) ? 1.0 : 0.0), 0.0, 1.0);\n" "}\n"; - GLuint program = CompileProgram(essl3_shaders::vs::Simple(), fragmentShaderSource); + GLuint program = CompileProgram(essl3_shaders::vs::Simple(), kFS); ASSERT_NE(0u, program); drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f); @@ -2099,7 +2079,7 @@ TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderShortCircuit) // Indexing the vector needs to be evaluated after func() for the right result. TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderDynamicVectorIndexingInLValue) { - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 my_FragColor;\n" @@ -2116,7 +2096,7 @@ TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderDynamicVectorIndexingInLValu " my_FragColor = vec4(0.0, (green ? 1.0 : 0.0), 0.0, 1.0);\n" "}\n"; - GLuint program = CompileProgram(essl3_shaders::vs::Simple(), fragmentShaderSource); + GLuint program = CompileProgram(essl3_shaders::vs::Simple(), kFS); ASSERT_NE(0u, program); drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f); @@ -2129,21 +2109,21 @@ TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderDynamicVectorIndexingInLValu // See http://anglebug.com/1380 TEST_P(GLSLTest, RenderTrisWithPointCoord) { - const std::string &vert = + constexpr char kVS[] = "attribute vec2 aPosition;\n" "void main()\n" "{\n" " gl_Position = vec4(aPosition, 0, 1);\n" " gl_PointSize = 1.0;\n" "}"; - const std::string &frag = + constexpr char kFS[] = "void main()\n" "{\n" " gl_FragColor = vec4(gl_PointCoord.xy, 0, 1);\n" " gl_FragColor = vec4(0, 1, 0, 1);\n" "}"; - ANGLE_GL_PROGRAM(prog, vert, frag); + ANGLE_GL_PROGRAM(prog, kVS, kFS); drawQuad(prog.get(), "aPosition", 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2151,7 +2131,7 @@ TEST_P(GLSLTest, RenderTrisWithPointCoord) // Convers a bug with the integer pow statement workaround. TEST_P(GLSLTest, NestedPowStatements) { - const std::string &frag = + constexpr char kFS[] = "precision mediump float;\n" "float func(float v)\n" "{\n" @@ -2164,7 +2144,7 @@ TEST_P(GLSLTest, NestedPowStatements) " gl_FragColor = abs(v - 36.0) < 0.001 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" "}"; - ANGLE_GL_PROGRAM(prog, essl1_shaders::vs::Simple(), frag); + ANGLE_GL_PROGRAM(prog, essl1_shaders::vs::Simple(), kFS); drawQuad(prog.get(), essl1_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2172,7 +2152,7 @@ TEST_P(GLSLTest, NestedPowStatements) // Test that -float calculation is correct. TEST_P(GLSLTest_ES3, UnaryMinusOperatorFloat) { - const std::string &frag = + constexpr char kFS[] = "#version 300 es\n" "out highp vec4 o_color;\n" "void main() {\n" @@ -2182,7 +2162,7 @@ TEST_P(GLSLTest_ES3, UnaryMinusOperatorFloat) " o_color = abs(v - 0.5) < 0.001 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" "}\n"; - ANGLE_GL_PROGRAM(prog, essl3_shaders::vs::Simple(), frag); + ANGLE_GL_PROGRAM(prog, essl3_shaders::vs::Simple(), kFS); drawQuad(prog.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2190,7 +2170,7 @@ TEST_P(GLSLTest_ES3, UnaryMinusOperatorFloat) // Test that atan(vec2, vec2) calculation is correct. TEST_P(GLSLTest_ES3, AtanVec2) { - const std::string &frag = + constexpr char kFS[] = "#version 300 es\n" "out highp vec4 o_color;\n" "void main() {\n" @@ -2201,7 +2181,7 @@ TEST_P(GLSLTest_ES3, AtanVec2) "vec4(1, 0, 0, 1);\n" "}\n"; - ANGLE_GL_PROGRAM(prog, essl3_shaders::vs::Simple(), frag); + ANGLE_GL_PROGRAM(prog, essl3_shaders::vs::Simple(), kFS); drawQuad(prog.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2209,7 +2189,7 @@ TEST_P(GLSLTest_ES3, AtanVec2) // Convers a bug with the unary minus operator on signed integer workaround. TEST_P(GLSLTest_ES3, UnaryMinusOperatorSignedInt) { - const std::string &vert = + constexpr char kVS[] = "#version 300 es\n" "in highp vec4 position;\n" "out mediump vec4 v_color;\n" @@ -2228,7 +2208,7 @@ TEST_P(GLSLTest_ES3, UnaryMinusOperatorSignedInt) " v_color = (result == 2) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" " gl_Position = position;\n" "}\n"; - const std::string &frag = + constexpr char kFS[] = "#version 300 es\n" "in mediump vec4 v_color;\n" "layout(location=0) out mediump vec4 o_color;\n" @@ -2236,7 +2216,7 @@ TEST_P(GLSLTest_ES3, UnaryMinusOperatorSignedInt) " o_color = v_color;\n" "}\n"; - ANGLE_GL_PROGRAM(prog, vert, frag); + ANGLE_GL_PROGRAM(prog, kVS, kFS); GLint oneIndex = glGetUniformLocation(prog.get(), "ui_one"); ASSERT_NE(-1, oneIndex); @@ -2256,7 +2236,7 @@ TEST_P(GLSLTest_ES3, UnaryMinusOperatorSignedInt) // Convers a bug with the unary minus operator on unsigned integer workaround. TEST_P(GLSLTest_ES3, UnaryMinusOperatorUnsignedInt) { - const std::string &vert = + constexpr char kVS[] = "#version 300 es\n" "in highp vec4 position;\n" "out mediump vec4 v_color;\n" @@ -2275,7 +2255,7 @@ TEST_P(GLSLTest_ES3, UnaryMinusOperatorUnsignedInt) " v_color = (result == 2u) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" " gl_Position = position;\n" "}\n"; - const std::string &frag = + constexpr char kFS[] = "#version 300 es\n" "in mediump vec4 v_color;\n" "layout(location=0) out mediump vec4 o_color;\n" @@ -2283,7 +2263,7 @@ TEST_P(GLSLTest_ES3, UnaryMinusOperatorUnsignedInt) " o_color = v_color;\n" "}\n"; - ANGLE_GL_PROGRAM(prog, vert, frag); + ANGLE_GL_PROGRAM(prog, kVS, kFS); GLint oneIndex = glGetUniformLocation(prog.get(), "ui_one"); ASSERT_NE(-1, oneIndex); @@ -2306,7 +2286,7 @@ TEST_P(GLSLTest, NestedSequenceOperatorWithTernaryInside) { // Note that the uniform keep_flop_positive doesn't need to be set - the test expects it to have // its default value false. - const std::string &frag = + constexpr char kFS[] = "precision mediump float;\n" "uniform bool keep_flop_positive;\n" "float flop;\n" @@ -2317,7 +2297,7 @@ TEST_P(GLSLTest, NestedSequenceOperatorWithTernaryInside) " gl_FragColor = vec4(0, -flop, 0, 1);\n" "}"; - ANGLE_GL_PROGRAM(prog, essl1_shaders::vs::Simple(), frag); + ANGLE_GL_PROGRAM(prog, essl1_shaders::vs::Simple(), kFS); drawQuad(prog.get(), essl1_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2327,26 +2307,24 @@ TEST_P(GLSLTest, ExternalAnd2DSampler) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_EGL_image_external")); - const std::string fragmentShader = - R"( - #extension GL_OES_EGL_image_external : enable - precision mediump float; - uniform samplerExternalOES tex0; - uniform sampler2D tex1; - void main(void) - { - vec2 uv = vec2(0.0, 0.0); - gl_FragColor = texture2D(tex0, uv) + texture2D(tex1, uv); - })"; + constexpr char kFS[] = R"(#extension GL_OES_EGL_image_external : enable +precision mediump float; +uniform samplerExternalOES tex0; +uniform sampler2D tex1; +void main(void) +{ + vec2 uv = vec2(0.0, 0.0); + gl_FragColor = texture2D(tex0, uv) + texture2D(tex1, uv); +})"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); } // Test that literal infinity can be written out from the shader translator. // A similar test can't be made for NaNs, since ESSL 3.00.6 requirements for NaNs are very loose. TEST_P(GLSLTest_ES3, LiteralInfinityOutput) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 out_color;\n" @@ -2358,7 +2336,7 @@ TEST_P(GLSLTest_ES3, LiteralInfinityOutput) " out_color = correct ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2367,7 +2345,7 @@ TEST_P(GLSLTest_ES3, LiteralInfinityOutput) // A similar test can't be made for NaNs, since ESSL 3.00.6 requirements for NaNs are very loose. TEST_P(GLSLTest_ES3, LiteralNegativeInfinityOutput) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 out_color;\n" @@ -2379,7 +2357,7 @@ TEST_P(GLSLTest_ES3, LiteralNegativeInfinityOutput) " out_color = correct ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2392,61 +2370,59 @@ TEST_P(GLSLTest_ES3, LiteralNegativeInfinityOutput) // Test that passes splitting multiple declarations and comma operators are correctly ordered. TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperator) { - const std::string &fragmentShader = - R"(#version 300 es - precision mediump float; - out vec4 color; + constexpr char kFS[] = R"(#version 300 es +precision mediump float; +out vec4 color; - uniform float u; - float c = 0.0; - float sideEffect() - { - c = u; - return c; - } +uniform float u; +float c = 0.0; +float sideEffect() +{ + c = u; + return c; +} - void main(void) - { - float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : sideEffect()), a); - color = vec4(b + c); - })"; +void main(void) +{ + float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : sideEffect()), a); + color = vec4(b + c); +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); } // Test that passes splitting multiple declarations and comma operators and for loops are // correctly ordered. TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperatorInForLoop) { - const std::string &fragmentShader = - R"(#version 300 es - precision mediump float; - out vec4 color; + constexpr char kFS[] = R"(#version 300 es +precision mediump float; +out vec4 color; - uniform float u; - float c = 0.0; - float sideEffect() - { - c = u; - return c; - } +uniform float u; +float c = 0.0; +float sideEffect() +{ + c = u; + return c; +} - void main(void) - { - for(float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : sideEffect()), a); a < 10.0; a++) - { - b += 1.0; - color = vec4(b); - } - })"; +void main(void) +{ + for(float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : sideEffect()), a); a < 10.0; a++) + { + b += 1.0; + color = vec4(b); + } +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); } // Test that splitting multiple declaration in for loops works with no loop condition TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyCondition) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -2460,13 +2436,13 @@ TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyCondition) " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); } // Test that splitting multiple declaration in for loops works with no loop expression TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyExpression) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -2480,14 +2456,14 @@ TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyExpression) " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); } // Test that dynamic indexing of a matrix inside a dynamic indexing of a vector in an l-value works // correctly. TEST_P(GLSLTest_ES3, NestedDynamicIndexingInLValue) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 my_FragColor;\n" @@ -2499,7 +2475,7 @@ TEST_P(GLSLTest_ES3, NestedDynamicIndexingInLValue) " my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2582,7 +2558,7 @@ TEST_P(GLSLTest_ES31, FindMSBAndFindLSBCornerCases) // Failing on N5X Oreo http://anglebug.com/2304 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); - const std::string &fragmentShader = + constexpr char kFS[] = "#version 310 es\n" "precision mediump float;\n" "out vec4 my_FragColor;\n" @@ -2598,7 +2574,7 @@ TEST_P(GLSLTest_ES31, FindMSBAndFindLSBCornerCases) " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl31_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2612,7 +2588,7 @@ TEST_P(GLSLTest_ES3, WriteIntoDynamicIndexingOfSwizzledVector) // The shader first assigns v.x to v.z (1.0) // Then v.y to v.y (2.0) // Then v.z to v.x (1.0) - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 my_FragColor;\n" @@ -2625,7 +2601,7 @@ TEST_P(GLSLTest_ES3, WriteIntoDynamicIndexingOfSwizzledVector) "0, 0, 1);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2639,7 +2615,7 @@ TEST_P(GLSLTest_ES3, NestedSamplingOperation) // Test skipped on Android because of bug with Nexus 5X. ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGLES()); - const std::string &vertexShader = + constexpr char kVS[] = "#version 300 es\n" "out vec2 texCoord;\n" "in vec2 position;\n" @@ -2649,7 +2625,7 @@ TEST_P(GLSLTest_ES3, NestedSamplingOperation) " texCoord = position * 0.5 + vec2(0.5);\n" "}\n"; - const std::string &simpleFragmentShader = + constexpr char kSimpleFS[] = "#version 300 es\n" "in mediump vec2 texCoord;\n" "out mediump vec4 fragColor;\n" @@ -2658,7 +2634,7 @@ TEST_P(GLSLTest_ES3, NestedSamplingOperation) " fragColor = vec4(texCoord, 0, 1);\n" "}\n"; - const std::string &nestedFragmentShader = + constexpr char kNestedFS[] = "#version 300 es\n" "uniform mediump sampler2D samplerA;\n" "uniform mediump sampler2D samplerB;\n" @@ -2669,8 +2645,8 @@ TEST_P(GLSLTest_ES3, NestedSamplingOperation) " fragColor = texture(samplerB, texture(samplerA, texCoord).xy);\n" "}\n"; - ANGLE_GL_PROGRAM(initProg, vertexShader, simpleFragmentShader); - ANGLE_GL_PROGRAM(nestedProg, vertexShader, nestedFragmentShader); + ANGLE_GL_PROGRAM(initProg, kVS, kSimpleFS); + ANGLE_GL_PROGRAM(nestedProg, kVS, kNestedFS); // Initialize a first texture with default texCoord data. GLTexture texA; @@ -2731,14 +2707,14 @@ TEST_P(GLSLTest_ES3, NestedSamplingOperation) // doesn't crash. TEST_P(GLSLTest, ConstantStatementInForLoop) { - const std::string &vertexShader = + constexpr char kVS[] = "void main()\n" "{\n" " for (int i = 0; i < 10; ++i)\n" " const int b = 0;\n" "}\n"; - GLuint shader = CompileShader(GL_VERTEX_SHADER, vertexShader); + GLuint shader = CompileShader(GL_VERTEX_SHADER, kVS); EXPECT_NE(0u, shader); glDeleteShader(shader); } @@ -2747,13 +2723,13 @@ TEST_P(GLSLTest, ConstantStatementInForLoop) // test doesn't work on D3D9 due to looping limitations, so it is only run on ES3. TEST_P(GLSLTest_ES3, ConstantStatementAsLoopInit) { - const std::string &vertexShader = + constexpr char kVS[] = "void main()\n" "{\n" " for (const int i = 0; i < 0;) {}\n" "}\n"; - GLuint shader = CompileShader(GL_VERTEX_SHADER, vertexShader); + GLuint shader = CompileShader(GL_VERTEX_SHADER, kVS); EXPECT_NE(0u, shader); glDeleteShader(shader); } @@ -2765,7 +2741,7 @@ TEST_P(GLSLTest_ES3, InitUninitializedLocals) // http://anglebug.com/2046 ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGLES()); - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 my_FragColor;\n" @@ -2789,7 +2765,7 @@ TEST_P(GLSLTest_ES3, InitUninitializedLocals) " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2802,7 +2778,7 @@ TEST_P(GLSLTest, InitUninitializedStructContainingArrays) // http://anglebug.com/2046 ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGLES()); - const std::string &fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "struct T\n" "{\n" @@ -2826,7 +2802,7 @@ TEST_P(GLSLTest, InitUninitializedStructContainingArrays) " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl1_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2886,7 +2862,7 @@ TEST_P(GLSLTest_ES3, UninitializedNamelessStructInForInitStatement) // http://anglebug.com/2046 ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGLES()); - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 my_FragColor;\n" @@ -2898,7 +2874,7 @@ TEST_P(GLSLTest_ES3, UninitializedNamelessStructInForInitStatement) " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2909,7 +2885,7 @@ TEST_P(WebGLGLSLTest, InitUninitializedGlobals) // http://anglebug.com/2862 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); - const std::string &fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "int result;\n" "int i[2], j = i[0] + 1;\n" @@ -2926,7 +2902,7 @@ TEST_P(WebGLGLSLTest, InitUninitializedGlobals) " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -2934,7 +2910,7 @@ TEST_P(WebGLGLSLTest, InitUninitializedGlobals) // Test that an uninitialized nameless struct in the global scope works. TEST_P(WebGLGLSLTest, UninitializedNamelessStructInGlobalScope) { - const std::string &fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "struct { float q; } b;\n" "void main()\n" @@ -2946,7 +2922,7 @@ TEST_P(WebGLGLSLTest, UninitializedNamelessStructInGlobalScope) " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3061,7 +3037,7 @@ void main() // Test that a loop condition that has an initializer declares a variable. TEST_P(GLSLTest_ES3, ConditionInitializerDeclaresVariable) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 my_FragColor;\n" @@ -3083,7 +3059,7 @@ TEST_P(GLSLTest_ES3, ConditionInitializerDeclaresVariable) " my_FragColor = vec4(i * 0.5 - 1.0, i * 0.5, 0.0, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3093,7 +3069,7 @@ TEST_P(GLSLTest_ES3, ConditionInitializerDeclaresVariable) // initializer if present, otherwise immediately following the identifier" TEST_P(GLSLTest, VariableHidesUserDefinedFunctionAfterInitializer) { - const std::string &fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "uniform vec4 u;\n" "vec4 foo()\n" @@ -3106,7 +3082,7 @@ TEST_P(GLSLTest, VariableHidesUserDefinedFunctionAfterInitializer) " gl_FragColor = foo + vec4(0, 1, 0, 1);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl1_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3114,7 +3090,7 @@ TEST_P(GLSLTest, VariableHidesUserDefinedFunctionAfterInitializer) // Test that structs with identical members are not ambiguous as function arguments. TEST_P(GLSLTest, StructsWithSameMembersDisambiguatedByName) { - const std::string &fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "uniform float u_zero;\n" "struct S { float foo; };\n" @@ -3130,7 +3106,7 @@ TEST_P(GLSLTest, StructsWithSameMembersDisambiguatedByName) " gl_FragColor = vec4(0.0, get(s) + get(s2), 0.0, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl1_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3139,7 +3115,7 @@ TEST_P(GLSLTest, StructsWithSameMembersDisambiguatedByName) // GLSL ES 3.00.6 section 4.3.10. TEST_P(GLSLTest_ES3, VaryingStructNotStaticallyUsedInFragmentShader) { - const std::string &vertexShader = + constexpr char kVS[] = "#version 300 es\n" "struct S {\n" " vec4 field;\n" @@ -3151,7 +3127,7 @@ TEST_P(GLSLTest_ES3, VaryingStructNotStaticallyUsedInFragmentShader) " varStruct.field = vec4(0.0, 0.5, 0.0, 0.0);\n" "}\n"; - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "struct S {\n" @@ -3164,14 +3140,14 @@ TEST_P(GLSLTest_ES3, VaryingStructNotStaticallyUsedInFragmentShader) " col = vec4(1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); } // Test that a varying struct that's not declared in the fragment shader links successfully. // GLSL ES 3.00.6 section 4.3.10. TEST_P(GLSLTest_ES3, VaryingStructNotDeclaredInFragmentShader) { - const std::string &vertexShader = + constexpr char kVS[] = "#version 300 es\n" "struct S {\n" " vec4 field;\n" @@ -3183,7 +3159,7 @@ TEST_P(GLSLTest_ES3, VaryingStructNotDeclaredInFragmentShader) " varStruct.field = vec4(0.0, 0.5, 0.0, 0.0);\n" "}\n"; - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 col;\n" @@ -3192,13 +3168,13 @@ TEST_P(GLSLTest_ES3, VaryingStructNotDeclaredInFragmentShader) " col = vec4(1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); } // Test that a varying struct that gets used in the fragment shader works. TEST_P(GLSLTest_ES3, VaryingStructUsedInFragmentShader) { - const std::string &vertexShader = + constexpr char kVS[] = "#version 300 es\n" "in vec4 inputAttribute;\n" "struct S {\n" @@ -3211,7 +3187,7 @@ TEST_P(GLSLTest_ES3, VaryingStructUsedInFragmentShader) " varStruct.field = vec4(0.0, 1.0, 0.0, 1.0);\n" "}\n"; - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 col;\n" @@ -3224,7 +3200,7 @@ TEST_P(GLSLTest_ES3, VaryingStructUsedInFragmentShader) " col = varStruct.field;\n" "}\n"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program.get(), "inputAttribute", 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3327,7 +3303,7 @@ TEST_P(GLSLTest, ArrayOfStructsWithSamplersAsFunctionArg) // Shader failed to compile on Android. http://anglebug.com/2114 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES()); - const std::string &fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "struct S\n" "{\n" @@ -3345,7 +3321,7 @@ TEST_P(GLSLTest, ArrayOfStructsWithSamplersAsFunctionArg) " gl_FragColor = foo(uStructs);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); // Initialize the texture with green. GLTexture tex; @@ -3381,7 +3357,7 @@ TEST_P(GLSLTest, StructWithSamplerArrayAsFunctionArg) // TODO(jmadill): Fix on Android if possible. http://anglebug.com/2703 ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan()); - const std::string &fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "struct S\n" "{\n" @@ -3399,7 +3375,7 @@ TEST_P(GLSLTest, StructWithSamplerArrayAsFunctionArg) " gl_FragColor = foo(uStruct);\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); // Initialize the texture with green. GLTexture tex; @@ -3662,7 +3638,7 @@ void main() // in global variable initialization. TEST_P(WebGLGLSLTest, GlobalVariableDeclaredAfterMain) { - const std::string &fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "int getFoo();\n" "uniform int u_zero;\n" @@ -3681,7 +3657,7 @@ TEST_P(WebGLGLSLTest, GlobalVariableDeclaredAfterMain) " return foo;\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3691,33 +3667,32 @@ TEST_P(WebGLGLSLTest, GlobalVariableDeclaredAfterMain) TEST_P(GLSLTest_ES3, ArrayLengthOnExpressionWithSideEffectsInLoopCondition) { // "a" gets doubled three times in the below program. - const std::string &fragmentShader = - R"(#version 300 es - precision highp float; - out vec4 my_FragColor; - uniform int u_zero; - int a; - int[2] doubleA() - { - a *= 2; - return int[2](a, a); - } - void main() - { - a = u_zero + 1; - for (int i = 0; i < doubleA().length(); ++i) - {} - if (a == 8) - { - my_FragColor = vec4(0, 1, 0, 1); - } - else - { - my_FragColor = vec4(1, 0, 0, 1); - } - })"; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +out vec4 my_FragColor; +uniform int u_zero; +int a; +int[2] doubleA() +{ + a *= 2; + return int[2](a, a); +} +void main() +{ + a = u_zero + 1; + for (int i = 0; i < doubleA().length(); ++i) + {} + if (a == 8) + { + my_FragColor = vec4(0, 1, 0, 1); + } + else + { + my_FragColor = vec4(1, 0, 0, 1); + } +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3727,32 +3702,31 @@ TEST_P(GLSLTest_ES3, ArrayLengthOnExpressionWithSideEffectsInLoopCondition) // operands need to run in order from left to right (ESSL 3.00.6 section 5.9). TEST_P(GLSLTest_ES3, ArrayLengthOnExpressionWithSideEffectsInSequence) { - const std::string &fragmentShader = - R"(#version 300 es - precision highp float; - out vec4 my_FragColor; - uniform int u_zero; - int a; - int[3] doubleA() - { - a *= 2; - return int[3](a, a, a); - } - void main() - { - a = u_zero; - int b = (a++, doubleA().length()); - if (b == 3 && a == 2) - { - my_FragColor = vec4(0, 1, 0, 1); - } - else - { - my_FragColor = vec4(1, 0, 0, 1); - } - })"; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +out vec4 my_FragColor; +uniform int u_zero; +int a; +int[3] doubleA() +{ + a *= 2; + return int[3](a, a, a); +} +void main() +{ + a = u_zero; + int b = (a++, doubleA().length()); + if (b == 3 && a == 2) + { + my_FragColor = vec4(0, 1, 0, 1); + } + else + { + my_FragColor = vec4(1, 0, 0, 1); + } +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3761,32 +3735,31 @@ TEST_P(GLSLTest_ES3, ArrayLengthOnExpressionWithSideEffectsInSequence) // Both "this" expressions also have side effects. TEST_P(GLSLTest_ES3, NestedArrayLengthMethodsWithSideEffects) { - const std::string &fragmentShader = - R"(#version 300 es - precision highp float; - out vec4 my_FragColor; - uniform int u_zero; - int a; - int[3] multiplyA(int multiplier) - { - a *= multiplier; - return int[3](a, a, a); - } - void main() - { - a = u_zero + 1; - int b = multiplyA(multiplyA(2).length()).length(); - if (b == 3 && a == 6) - { - my_FragColor = vec4(0, 1, 0, 1); - } - else - { - my_FragColor = vec4(1, 0, 0, 1); - } - })"; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +out vec4 my_FragColor; +uniform int u_zero; +int a; +int[3] multiplyA(int multiplier) +{ + a *= multiplier; + return int[3](a, a, a); +} +void main() +{ + a = u_zero + 1; + int b = multiplyA(multiplyA(2).length()).length(); + if (b == 3 && a == 6) + { + my_FragColor = vec4(0, 1, 0, 1); + } + else + { + my_FragColor = vec4(1, 0, 0, 1); + } +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3794,60 +3767,53 @@ TEST_P(GLSLTest_ES3, NestedArrayLengthMethodsWithSideEffects) // Test that statements inside switch() get translated to correct HLSL. TEST_P(GLSLTest_ES3, DifferentStatementsInsideSwitch) { - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es +precision highp float; +uniform int u; +void main() +{ + switch (u) + { + case 0: + ivec2 i; + i.yx; + } +})"; - precision highp float; - - uniform int u; - - void main() - { - switch (u) - { - case 0: - ivec2 i; - i.yx; - } - })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); } // Test that switch fall-through works correctly. // This is a regression test for http://anglebug.com/2178 TEST_P(GLSLTest_ES3, SwitchFallThroughCodeDuplication) { - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es +precision highp float; +out vec4 my_FragColor; +uniform int u_zero; - precision highp float; +void main() +{ + int i = 0; + // switch should fall through both cases. + switch(u_zero) + { + case 0: + i += 1; + case 1: + i += 2; + } + if (i == 3) + { + my_FragColor = vec4(0, 1, 0, 1); + } + else + { + my_FragColor = vec4(1, 0, 0, 1); + } +})"; - out vec4 my_FragColor; - - uniform int u_zero; - - void main() - { - int i = 0; - // switch should fall through both cases. - switch(u_zero) - { - case 0: - i += 1; - case 1: - i += 2; - } - if (i == 3) - { - my_FragColor = vec4(0, 1, 0, 1); - } - else - { - my_FragColor = vec4(1, 0, 0, 1); - } - })"; - - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3855,83 +3821,80 @@ TEST_P(GLSLTest_ES3, SwitchFallThroughCodeDuplication) // Test that a switch statement with an empty block inside as a final statement compiles. TEST_P(GLSLTest_ES3, SwitchFinalCaseHasEmptyBlock) { - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es - precision mediump float; - uniform int i; - void main() - { - switch (i) - { - case 0: - break; - default: - {} - } - })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); +precision mediump float; +uniform int i; +void main() +{ + switch (i) + { + case 0: + break; + default: + {} + } +})"; + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); } // Test that a switch statement with an empty declaration inside as a final statement compiles. TEST_P(GLSLTest_ES3, SwitchFinalCaseHasEmptyDeclaration) { - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es - precision mediump float; - uniform int i; - void main() - { - switch (i) - { - case 0: - break; - default: - float; - } - })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); +precision mediump float; +uniform int i; +void main() +{ + switch (i) + { + case 0: + break; + default: + float; + } +})"; + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); } // Test switch/case where break/return statements are within blocks. TEST_P(GLSLTest_ES3, SwitchBreakOrReturnInsideBlocks) { - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es - precision highp float; +precision highp float; - uniform int u_zero; - out vec4 my_FragColor; +uniform int u_zero; +out vec4 my_FragColor; - bool test(int n) +bool test(int n) +{ + switch(n) { + case 0: { - switch(n) { - case 0: - { - { - break; - } - } - case 1: - { - return true; - } - case 2: - { - n++; - } + { + break; } - return false; } - - void main() + case 1: { - my_FragColor = test(u_zero + 1) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); - })"; + return true; + } + case 2: + { + n++; + } + } + return false; +} - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); +void main() +{ + my_FragColor = test(u_zero + 1) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); +})"; + + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3940,28 +3903,27 @@ TEST_P(GLSLTest_ES3, SwitchBreakOrReturnInsideBlocks) // subsequent case. TEST_P(GLSLTest_ES3, SwitchWithVariableDeclarationInside) { - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es - precision highp float; - out vec4 my_FragColor; +precision highp float; +out vec4 my_FragColor; - uniform int u_zero; +uniform int u_zero; - void main() - { - my_FragColor = vec4(1, 0, 0, 1); - switch (u_zero) - { - case 0: - ivec2 i; - i = ivec2(1, 0); - default: - my_FragColor = vec4(0, i[0], 0, 1); - } - })"; +void main() +{ + my_FragColor = vec4(1, 0, 0, 1); + switch (u_zero) + { + case 0: + ivec2 i; + i = ivec2(1, 0); + default: + my_FragColor = vec4(0, i[0], 0, 1); + } +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -3970,37 +3932,36 @@ TEST_P(GLSLTest_ES3, SwitchWithVariableDeclarationInside) // subsequent case. TEST_P(GLSLTest_ES3, NestedSwitchWithVariableDeclarationInside) { - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es - precision highp float; - out vec4 my_FragColor; +precision highp float; +out vec4 my_FragColor; - uniform int u_zero; - uniform int u_zero2; +uniform int u_zero; +uniform int u_zero2; - void main() - { - my_FragColor = vec4(1, 0, 0, 1); - switch (u_zero) +void main() +{ + my_FragColor = vec4(1, 0, 0, 1); + switch (u_zero) + { + case 0: + ivec2 i; + i = ivec2(1, 0); + switch (u_zero2) { case 0: - ivec2 i; - i = ivec2(1, 0); - switch (u_zero2) - { - case 0: - int j; - default: - j = 1; - i *= j; - } + int j; default: - my_FragColor = vec4(0, i[0], 0, 1); + j = 1; + i *= j; } - })"; + default: + my_FragColor = vec4(0, i[0], 0, 1); + } +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -4009,22 +3970,21 @@ TEST_P(GLSLTest_ES3, NestedSwitchWithVariableDeclarationInside) // init-statement. TEST_P(GLSLTest_ES3, EmptySwitch) { - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es - precision highp float; +precision highp float; - uniform int u_zero; - out vec4 my_FragColor; +uniform int u_zero; +out vec4 my_FragColor; - void main() - { - int i = u_zero; - switch(++i) {} - my_FragColor = (i == 1) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); - })"; +void main() +{ + int i = u_zero; + switch(++i) {} + my_FragColor = (i == 1) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -4035,33 +3995,32 @@ TEST_P(GLSLTest_ES3, ConstStructInsideExpression) // Incorrect output color was seen on Android. http://anglebug.com/2226 ANGLE_SKIP_TEST_IF(IsAndroid() && !IsNVIDIA() && IsOpenGLES()); - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es - precision highp float; - out vec4 my_FragColor; +precision highp float; +out vec4 my_FragColor; - uniform float u_zero; +uniform float u_zero; - struct S - { - float field; - }; +struct S +{ + float field; +}; - void main() - { - const S constS = S(1.0); - S nonConstS = constS; - nonConstS.field = u_zero; - bool fail = (constS == nonConstS); - my_FragColor = vec4(0, 1, 0, 1); - if (fail) - { - my_FragColor = vec4(1, 0, 0, 1); - } - })"; +void main() +{ + const S constS = S(1.0); + S nonConstS = constS; + nonConstS.field = u_zero; + bool fail = (constS == nonConstS); + my_FragColor = vec4(0, 1, 0, 1); + if (fail) + { + my_FragColor = vec4(1, 0, 0, 1); + } +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -4069,43 +4028,41 @@ TEST_P(GLSLTest_ES3, ConstStructInsideExpression) // Test that a varying struct that's defined as a part of the declaration is handled correctly. TEST_P(GLSLTest_ES3, VaryingStructWithInlineDefinition) { - const std::string &vertexShader = - R"(#version 300 es - in vec4 inputAttribute; + constexpr char kVS[] = R"(#version 300 es +in vec4 inputAttribute; - flat out struct S - { - int field; - } v_s; +flat out struct S +{ + int field; +} v_s; - void main() - { - v_s.field = 1; - gl_Position = inputAttribute; - })"; +void main() +{ + v_s.field = 1; + gl_Position = inputAttribute; +})"; - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es - precision highp float; - out vec4 my_FragColor; +precision highp float; +out vec4 my_FragColor; - flat in struct S - { - int field; - } v_s; +flat in struct S +{ + int field; +} v_s; - void main() - { - bool success = (v_s.field == 1); - my_FragColor = vec4(1, 0, 0, 1); - if (success) - { - my_FragColor = vec4(0, 1, 0, 1); - } - })"; +void main() +{ + bool success = (v_s.field == 1); + my_FragColor = vec4(1, 0, 0, 1); + if (success) + { + my_FragColor = vec4(0, 1, 0, 1); + } +})"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program.get(), "inputAttribute", 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -4115,26 +4072,23 @@ TEST_P(GLSLTest_ES3, VaryingStructWithInlineDefinition) // VectorizeVectorScalarArithmetic AST transform. TEST_P(GLSLTest, VectorScalarMultiplyAndAddInLoop) { - const std::string &fragmentShader = - R"( + constexpr char kFS[] = R"(precision mediump float; - precision mediump float; +void main() { + gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < 2; i++) + { + gl_FragColor += (2.0 * gl_FragCoord.x); + } + if (gl_FragColor.g == gl_FragColor.r && + gl_FragColor.b == gl_FragColor.r && + gl_FragColor.a == gl_FragColor.r) + { + gl_FragColor = vec4(0, 1, 0, 1); + } +})"; - void main() { - gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); - for (int i = 0; i < 2; i++) - { - gl_FragColor += (2.0 * gl_FragCoord.x); - } - if (gl_FragColor.g == gl_FragColor.r && - gl_FragColor.b == gl_FragColor.r && - gl_FragColor.a == gl_FragColor.r) - { - gl_FragColor = vec4(0, 1, 0, 1); - } - })"; - - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl1_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -4144,27 +4098,24 @@ TEST_P(GLSLTest, VectorScalarMultiplyAndAddInLoop) // VectorizeVectorScalarArithmetic AST transform. TEST_P(GLSLTest, VectorScalarDivideAndAddInLoop) { - const std::string &fragmentShader = - R"( + constexpr char kFS[] = R"(precision mediump float; - precision mediump float; +void main() { + gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < 2; i++) + { + float x = gl_FragCoord.x; + gl_FragColor = gl_FragColor + (x /= 2.0); + } + if (gl_FragColor.g == gl_FragColor.r && + gl_FragColor.b == gl_FragColor.r && + gl_FragColor.a == gl_FragColor.r) + { + gl_FragColor = vec4(0, 1, 0, 1); + } +})"; - void main() { - gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); - for (int i = 0; i < 2; i++) - { - float x = gl_FragCoord.x; - gl_FragColor = gl_FragColor + (x /= 2.0); - } - if (gl_FragColor.g == gl_FragColor.r && - gl_FragColor.b == gl_FragColor.r && - gl_FragColor.a == gl_FragColor.r) - { - gl_FragColor = vec4(0, 1, 0, 1); - } - })"; - - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl1_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -4173,33 +4124,31 @@ TEST_P(GLSLTest, VectorScalarDivideAndAddInLoop) // is handled correctly. TEST_P(GLSLTest_ES3, FlatVaryingUsedInFoldedTernary) { - const std::string &vertexShader = - R"(#version 300 es + constexpr char kVS[] = R"(#version 300 es - in vec4 inputAttribute; +in vec4 inputAttribute; - flat out int v; +flat out int v; - void main() - { - v = 1; - gl_Position = inputAttribute; - })"; +void main() +{ + v = 1; + gl_Position = inputAttribute; +})"; - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es - precision highp float; - out vec4 my_FragColor; +precision highp float; +out vec4 my_FragColor; - flat in int v; +flat in int v; - void main() - { - my_FragColor = vec4(0, (true ? v : 0), 0, 1); - })"; +void main() +{ + my_FragColor = vec4(0, (true ? v : 0), 0, 1); +})"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program.get(), "inputAttribute", 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } @@ -4208,29 +4157,23 @@ TEST_P(GLSLTest_ES3, FlatVaryingUsedInFoldedTernary) // finished. TEST_P(GLSLTest, ClearLinkErrorLog) { - const std::string &vertexShader = - R"( + constexpr char kVS[] = R"(attribute vec4 vert_in; +varying vec4 vert_out; +void main() +{ + gl_Position = vert_in; + vert_out = vert_in; +})"; - attribute vec4 vert_in; - varying vec4 vert_out; - void main() - { - gl_Position = vert_in; - vert_out = vert_in; - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec4 frag_in; +void main() +{ + gl_FragColor = frag_in; +})"; - const std::string &fragmentShader = - R"( - - precision mediump float; - varying vec4 frag_in; - void main() - { - gl_FragColor = frag_in; - })"; - - GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader); + GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); GLuint program = glCreateProgram(); @@ -4266,103 +4209,88 @@ TEST_P(GLSLTest, ClearLinkErrorLog) // Validate error messages when the link mismatch occurs on the type of a non-struct varying. TEST_P(GLSLTest, ErrorMessageOfVaryingMismatch) { - const std::string &vertexShader = - R"( + constexpr char kVS[] = R"(attribute vec4 inputAttribute; +varying vec4 vertex_out; +void main() +{ + vertex_out = inputAttribute; + gl_Position = inputAttribute; +})"; - attribute vec4 inputAttribute; - varying vec4 vertex_out; - void main() - { - vertex_out = inputAttribute; - gl_Position = inputAttribute; - })"; + constexpr char kFS[] = R"(precision mediump float; +varying float vertex_out; +void main() +{ + gl_FragColor = vec4(vertex_out, 0.0, 0.0, 1.0); +})"; - const std::string &fragmentShader = - R"( - - precision mediump float; - varying float vertex_out; - void main() - { - gl_FragColor = vec4(vertex_out, 0.0, 0.0, 1.0); - })"; - - validateComponentsInErrorMessage(vertexShader, fragmentShader, "Types", "varying 'vertex_out'"); + validateComponentsInErrorMessage(kVS, kFS, "Types", "varying 'vertex_out'"); } // Validate error messages when the link mismatch occurs on the name of a varying field. TEST_P(GLSLTest_ES3, ErrorMessageOfVaryingStructFieldNameMismatch) { - const std::string &vertexShader = - R"(#version 300 es + constexpr char kVS[] = R"(#version 300 es +in vec4 inputAttribute; +struct S { + float val1; + vec4 val2; +}; +out S vertex_out; +void main() +{ + vertex_out.val2 = inputAttribute; + vertex_out.val1 = inputAttribute[0]; + gl_Position = inputAttribute; +})"; - in vec4 inputAttribute; - struct S { - float val1; - vec4 val2; - }; - out S vertex_out; - void main() - { - vertex_out.val2 = inputAttribute; - vertex_out.val1 = inputAttribute[0]; - gl_Position = inputAttribute; - })"; + constexpr char kFS[] = R"(#version 300 es +precision mediump float; +struct S { + float val1; + vec4 val3; +}; +in S vertex_out; +layout (location = 0) out vec4 frag_out; +void main() +{ + frag_out = vec4(vertex_out.val1, 0.0, 0.0, 1.0); +})"; - const std::string &fragmentShader = - R"(#version 300 es - - precision mediump float; - struct S { - float val1; - vec4 val3; - }; - in S vertex_out; - layout (location = 0) out vec4 frag_out; - void main() - { - frag_out = vec4(vertex_out.val1, 0.0, 0.0, 1.0); - })"; - - validateComponentsInErrorMessage(vertexShader, fragmentShader, "Field names", - "varying 'vertex_out'"); + validateComponentsInErrorMessage(kVS, kFS, "Field names", "varying 'vertex_out'"); } // Validate error messages when the link mismatch occurs on the type of a varying field. TEST_P(GLSLTest_ES3, ErrorMessageOfVaryingStructFieldMismatch) { - const std::string &vertexShader = - R"(#version 300 es + constexpr char kVS[] = R"(#version 300 es +in vec4 inputAttribute; +struct S { + float val1; + vec4 val2; +}; +out S vertex_out; +void main() +{ + vertex_out.val2 = inputAttribute; + vertex_out.val1 = inputAttribute[0]; + gl_Position = inputAttribute; +})"; - in vec4 inputAttribute; - struct S { - float val1; - vec4 val2; - }; - out S vertex_out; - void main() - { - vertex_out.val2 = inputAttribute; - vertex_out.val1 = inputAttribute[0]; - gl_Position = inputAttribute; - })"; + constexpr char kFS[] = R"(#version 300 es +precision mediump float; +struct S { + float val1; + vec2 val2; +}; +in S vertex_out; +layout (location = 0) out vec4 frag_out; +void main() +{ + frag_out = vec4(vertex_out.val1, 0.0, 0.0, 1.0); +})"; - const std::string &fragmentShader = - R"(#version 300 es - - precision mediump float; - struct S { - float val1; - vec2 val2; - }; - in S vertex_out; - layout (location = 0) out vec4 frag_out; - void main() - { - frag_out = vec4(vertex_out.val1, 0.0, 0.0, 1.0); - })"; - - validateComponentsInErrorMessage(vertexShader, fragmentShader, "Types", + validateComponentsInErrorMessage(kVS, kFS, "Types", "varying 'vertex_out' member 'vertex_out.val2'"); } @@ -4370,201 +4298,179 @@ TEST_P(GLSLTest_ES3, ErrorMessageOfVaryingStructFieldMismatch) // field. TEST_P(GLSLTest, ErrorMessageOfLinkUniformStructFieldNameMismatch) { - const std::string &vertexShader = - R"( + constexpr char kVS[] = R"( +struct T +{ + vec2 t1; + vec3 t2; +}; +struct S { + T val1; + vec4 val2; +}; +uniform S uni; - struct T - { - vec2 t1; - vec3 t2; - }; - struct S { - T val1; - vec4 val2; - }; - uniform S uni; +attribute vec4 inputAttribute; +varying vec4 vertex_out; +void main() +{ + vertex_out = uni.val2; + gl_Position = inputAttribute; +})"; - attribute vec4 inputAttribute; - varying vec4 vertex_out; - void main() - { - vertex_out = uni.val2; - gl_Position = inputAttribute; - })"; + constexpr char kFS[] = R"(precision highp float; +struct T +{ + vec2 t1; + vec3 t3; +}; +struct S { + T val1; + vec4 val2; +}; +uniform S uni; - const std::string &fragmentShader = - R"( +varying vec4 vertex_out; +void main() +{ + gl_FragColor = vec4(uni.val1.t1[0], 0.0, 0.0, 1.0); +})"; - precision highp float; - struct T - { - vec2 t1; - vec3 t3; - }; - struct S { - T val1; - vec4 val2; - }; - uniform S uni; - - varying vec4 vertex_out; - void main() - { - gl_FragColor = vec4(uni.val1.t1[0], 0.0, 0.0, 1.0); - })"; - - validateComponentsInErrorMessage(vertexShader, fragmentShader, "Field names", - "uniform 'uni' member 'uni.val1'"); + validateComponentsInErrorMessage(kVS, kFS, "Field names", "uniform 'uni' member 'uni.val1'"); } // Validate error messages when the link mismatch occurs on the type of a non-struct uniform block // field. TEST_P(GLSLTest_ES3, ErrorMessageOfLinkInterfaceBlockFieldMismatch) { - const std::string &vertexShader = - R"(#version 300 es + constexpr char kVS[] = R"(#version 300 es +uniform S { + vec2 val1; + vec4 val2; +} uni; - uniform S { - vec2 val1; - vec4 val2; - } uni; +in vec4 inputAttribute; +out vec4 vertex_out; +void main() +{ + vertex_out = uni.val2; + gl_Position = inputAttribute; +})"; - in vec4 inputAttribute; - out vec4 vertex_out; - void main() - { - vertex_out = uni.val2; - gl_Position = inputAttribute; - })"; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +uniform S { + vec2 val1; + vec3 val2; +} uni; - const std::string &fragmentShader = - R"(#version 300 es +in vec4 vertex_out; +layout (location = 0) out vec4 frag_out; +void main() +{ + frag_out = vec4(uni.val1[0], 0.0, 0.0, 1.0); +})"; - precision highp float; - uniform S { - vec2 val1; - vec3 val2; - } uni; - - in vec4 vertex_out; - layout (location = 0) out vec4 frag_out; - void main() - { - frag_out = vec4(uni.val1[0], 0.0, 0.0, 1.0); - })"; - - validateComponentsInErrorMessage(vertexShader, fragmentShader, "Types", - "uniform block 'S' member 'S.val2'"); + validateComponentsInErrorMessage(kVS, kFS, "Types", "uniform block 'S' member 'S.val2'"); } // Validate error messages when the link mismatch occurs on the type of a member of a uniform block // struct field. TEST_P(GLSLTest_ES3, ErrorMessageOfLinkInterfaceBlockStructFieldMismatch) { - const std::string &vertexShader = - R"(#version 300 es + constexpr char kVS[] = R"(#version 300 es +struct T +{ + vec2 t1; + vec3 t2; +}; +uniform S { + T val1; + vec4 val2; +} uni; - struct T - { - vec2 t1; - vec3 t2; - }; - uniform S { - T val1; - vec4 val2; - } uni; +in vec4 inputAttribute; +out vec4 vertex_out; +void main() +{ + vertex_out = uni.val2; + gl_Position = inputAttribute; +})"; - in vec4 inputAttribute; - out vec4 vertex_out; - void main() - { - vertex_out = uni.val2; - gl_Position = inputAttribute; - })"; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +struct T +{ + vec2 t1; + vec4 t2; +}; +uniform S { + T val1; + vec4 val2; +} uni; - const std::string &fragmentShader = - R"(#version 300 es +in vec4 vertex_out; +layout (location = 0) out vec4 frag_out; +void main() +{ + frag_out = vec4(uni.val1.t1[0], 0.0, 0.0, 1.0); +})"; - precision highp float; - struct T - { - vec2 t1; - vec4 t2; - }; - uniform S { - T val1; - vec4 val2; - } uni; - - in vec4 vertex_out; - layout (location = 0) out vec4 frag_out; - void main() - { - frag_out = vec4(uni.val1.t1[0], 0.0, 0.0, 1.0); - })"; - - validateComponentsInErrorMessage(vertexShader, fragmentShader, "Types", - "uniform block 'S' member 'S.val1.t2'"); + validateComponentsInErrorMessage(kVS, kFS, "Types", "uniform block 'S' member 'S.val1.t2'"); } // Test a vertex shader that doesn't declare any varyings with a fragment shader that statically // uses a varying, but in a statement that gets trivially optimized out by the compiler. TEST_P(GLSLTest_ES3, FragmentShaderStaticallyUsesVaryingMissingFromVertex) { - const std::string &vertexShader = - R"(#version 300 es + constexpr char kVS[] = R"(#version 300 es +precision mediump float; - precision mediump float; +void main() +{ + gl_Position = vec4(0, 1, 0, 1); +})"; - void main() - { - gl_Position = vec4(0, 1, 0, 1); - })"; + constexpr char kFS[] = R"(#version 300 es +precision mediump float; +in float foo; +out vec4 my_FragColor; - const std::string &fragmentShader = - R"(#version 300 es +void main() +{ + if (false) + { + float unreferenced = foo; + } + my_FragColor = vec4(0, 1, 0, 1); +})"; - precision mediump float; - in float foo; - out vec4 my_FragColor; - - void main() - { - if (false) - { - float unreferenced = foo; - } - my_FragColor = vec4(0, 1, 0, 1); - })"; - - validateComponentsInErrorMessage(vertexShader, fragmentShader, "does not match any", "foo"); + validateComponentsInErrorMessage(kVS, kFS, "does not match any", "foo"); } // Test a varying that is statically used but not active in the fragment shader. TEST_P(GLSLTest_ES3, VaryingStaticallyUsedButNotActiveInFragmentShader) { - const std::string &vertexShader = - R"(#version 300 es - precision mediump float; - in vec4 iv; - out vec4 v; - void main() - { - gl_Position = iv; - v = iv; - })"; + constexpr char kVS[] = R"(#version 300 es +precision mediump float; +in vec4 iv; +out vec4 v; +void main() +{ + gl_Position = iv; + v = iv; +})"; - const std::string &fragmentShader = - R"(#version 300 es - precision mediump float; - in vec4 v; - out vec4 color; - void main() - { - color = true ? vec4(0.0) : v; - })"; + constexpr char kFS[] = R"(#version 300 es +precision mediump float; +in vec4 v; +out vec4 color; +void main() +{ + color = true ? vec4(0.0) : v; +})"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); } // Test nesting floor() calls with a large multiplier inside. @@ -4574,21 +4480,20 @@ TEST_P(GLSLTest_ES3, NestedFloorWithLargeMultiplierInside) // up red. http://crbug.com/838885 ANGLE_SKIP_TEST_IF(IsD3D11()); - const std::string &fragmentShader = - R"(#version 300 es - precision highp float; - out vec4 my_FragColor; - void main() - { - vec2 coord = gl_FragCoord.xy / 500.0; - my_FragColor = vec4(1, 0, 0, 1); - if (coord.y + 0.1 > floor(1e-6 * floor(coord.x*4e5))) - { - my_FragColor = vec4(0, 1, 0, 1); - } - })"; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +out vec4 my_FragColor; +void main() +{ + vec2 coord = gl_FragCoord.xy / 500.0; + my_FragColor = vec4(1, 0, 0, 1); + if (coord.y + 0.1 > floor(1e-6 * floor(coord.x*4e5))) + { + my_FragColor = vec4(0, 1, 0, 1); + } +})"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); // Verify that all the corners of the rendered result are green. EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); @@ -4711,7 +4616,7 @@ TEST_P(GLSLTest_ES31, ExceedCombinedShaderOutputResourcesInVSAndFS) } fragmentStream << "}\n"; - GLuint program = CompileProgram(vertexStream.str(), fragmentStream.str()); + GLuint program = CompileProgram(vertexStream.str().c_str(), fragmentStream.str().c_str()); EXPECT_EQ(0u, program); ASSERT_GL_NO_ERROR(); @@ -4721,31 +4626,29 @@ TEST_P(GLSLTest_ES31, ExceedCombinedShaderOutputResourcesInVSAndFS) // function works correctly. TEST_P(GLSLTest_ES3, AssignAssignmentToSwizzled) { - const std::string &fragmentShader = - R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es +precision highp float; +out vec4 my_FragColor; - precision highp float; - out vec4 my_FragColor; +uniform float uzero; - uniform float uzero; +vec3 fun(float s, float v) +{ + vec3 r = vec3(0); + if (s < 1.0) { + r.x = r.y = r.z = v; + return r; + } + return r; +} - vec3 fun(float s, float v) - { - vec3 r = vec3(0); - if (s < 1.0) { - r.x = r.y = r.z = v; - return r; - } - return r; - } +void main() +{ + my_FragColor.a = 1.0; + my_FragColor.rgb = fun(uzero, 1.0); +})"; - void main() - { - my_FragColor.a = 1.0; - my_FragColor.rgb = fun(uzero, 1.0); - })"; - - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); drawQuad(program.get(), essl3_shaders::PositionAttrib(), 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white); } @@ -4754,32 +4657,30 @@ TEST_P(GLSLTest_ES3, AssignAssignmentToSwizzled) // executed). Regression test for http://anglebug.com/2325 TEST_P(GLSLTest, IfElseIfAndReturn) { - const std::string &vertexShader = - R"(attribute vec4 a_position; - varying vec2 vPos; - void main() - { - gl_Position = a_position; - vPos = a_position.xy; - })"; + constexpr char kVS[] = R"(attribute vec4 a_position; +varying vec2 vPos; +void main() +{ + gl_Position = a_position; + vPos = a_position.xy; +})"; - const std::string &fragmentShader = - R"(precision mediump float; - varying vec2 vPos; - void main() - { - if (vPos.x < 1.0) // This colors the whole canvas green - { - gl_FragColor = vec4(0, 1, 0, 1); - return; - } - else if (vPos.x < 1.1) // This should have no effect - { - gl_FragColor = vec4(1, 0, 0, 1); - } - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 vPos; +void main() +{ + if (vPos.x < 1.0) // This colors the whole canvas green + { + gl_FragColor = vec4(0, 1, 0, 1); + return; + } + else if (vPos.x < 1.1) // This should have no effect + { + gl_FragColor = vec4(1, 0, 0, 1); + } +})"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program.get(), "a_position", 0.5f); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); } diff --git a/src/tests/gl_tests/GeometryShaderTest.cpp b/src/tests/gl_tests/GeometryShaderTest.cpp index dc6ee4676..ae3a32f24 100644 --- a/src/tests/gl_tests/GeometryShaderTest.cpp +++ b/src/tests/gl_tests/GeometryShaderTest.cpp @@ -65,27 +65,26 @@ TEST_P(GeometryShaderTest, CreateAndAttachGeometryShader) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader")); - const std::string &geometryShaderSource = - R"(#version 310 es - #extension GL_EXT_geometry_shader : require - layout (invocations = 3, triangles) in; - layout (triangle_strip, max_vertices = 3) out; - in vec4 texcoord[]; - out vec4 o_texcoord; - void main() - { - int n; - for (n = 0; n < gl_in.length(); n++) - { - gl_Position = gl_in[n].gl_Position; - gl_Layer = gl_InvocationID; - o_texcoord = texcoord[n]; - EmitVertex(); - } - EndPrimitive(); - })"; + constexpr char kGS[] = R"(#version 310 es +#extension GL_EXT_geometry_shader : require +layout (invocations = 3, triangles) in; +layout (triangle_strip, max_vertices = 3) out; +in vec4 texcoord[]; +out vec4 o_texcoord; +void main() +{ + int n; + for (n = 0; n < gl_in.length(); n++) + { + gl_Position = gl_in[n].gl_Position; + gl_Layer = gl_InvocationID; + o_texcoord = texcoord[n]; + EmitVertex(); + } + EndPrimitive(); +})"; - GLuint geometryShader = CompileShader(GL_GEOMETRY_SHADER_EXT, geometryShaderSource); + GLuint geometryShader = CompileShader(GL_GEOMETRY_SHADER_EXT, kGS); EXPECT_NE(0u, geometryShader); @@ -195,7 +194,7 @@ TEST_P(GeometryShaderTest, LinkWhenShaderVersionMismatch) const std::string &emptyGeometryShader = CreateEmptyGeometryShader("points", "points", 2, 1); - GLuint program = CompileProgramWithGS(essl3_shaders::vs::Simple(), emptyGeometryShader, + GLuint program = CompileProgramWithGS(essl3_shaders::vs::Simple(), emptyGeometryShader.c_str(), essl3_shaders::fs::Red()); EXPECT_EQ(0u, program); } @@ -206,30 +205,30 @@ TEST_P(GeometryShaderTest, LinkValidationOnGeometryShaderLayouts) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader")); - const std::string &gsWithoutInputPrimitive = CreateEmptyGeometryShader("", "points", 2, 1); - const std::string &gsWithoutOutputPrimitive = CreateEmptyGeometryShader("points", "", 2, 1); - const std::string &gsWithoutInvocations = CreateEmptyGeometryShader("points", "points", -1, 1); - const std::string &gsWithoutMaxVertices = CreateEmptyGeometryShader("points", "points", 2, -1); + const std::string gsWithoutInputPrimitive = CreateEmptyGeometryShader("", "points", 2, 1); + const std::string gsWithoutOutputPrimitive = CreateEmptyGeometryShader("points", "", 2, 1); + const std::string gsWithoutInvocations = CreateEmptyGeometryShader("points", "points", -1, 1); + const std::string gsWithoutMaxVertices = CreateEmptyGeometryShader("points", "points", 2, -1); // Linking a program with a geometry shader that only lacks 'invocations' should not cause a // link failure. - GLuint program = CompileProgramWithGS(essl31_shaders::vs::Simple(), gsWithoutInvocations, - essl31_shaders::fs::Red()); + GLuint program = CompileProgramWithGS(essl31_shaders::vs::Simple(), + gsWithoutInvocations.c_str(), essl31_shaders::fs::Red()); EXPECT_NE(0u, program); glDeleteProgram(program); // Linking a program with a geometry shader that lacks input primitive, output primitive or // 'max_vertices' causes a link failure. - program = CompileProgramWithGS(essl31_shaders::vs::Simple(), gsWithoutInputPrimitive, + program = CompileProgramWithGS(essl31_shaders::vs::Simple(), gsWithoutInputPrimitive.c_str(), essl31_shaders::fs::Red()); EXPECT_EQ(0u, program); - program = CompileProgramWithGS(essl31_shaders::vs::Simple(), gsWithoutOutputPrimitive, + program = CompileProgramWithGS(essl31_shaders::vs::Simple(), gsWithoutOutputPrimitive.c_str(), essl31_shaders::fs::Red()); EXPECT_EQ(0u, program); - program = CompileProgramWithGS(essl31_shaders::vs::Simple(), gsWithoutMaxVertices, + program = CompileProgramWithGS(essl31_shaders::vs::Simple(), gsWithoutMaxVertices.c_str(), essl31_shaders::fs::Red()); EXPECT_EQ(0u, program); @@ -242,43 +241,40 @@ TEST_P(GeometryShaderTest, VertexShaderArrayOutput) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader")); - const std::string &vertexShader = - R"(#version 310 es - in vec4 vertex_in; - out vec4 vertex_out[3]; - void main() - { - gl_Position = vertex_in; - vertex_out[0] = vec4(1.0, 0.0, 0.0, 1.0); - vertex_out[1] = vec4(0.0, 1.0, 0.0, 1.0); - vertex_out[2] = vec4(0.0, 0.0, 1.0, 1.0); - })"; + constexpr char kVS[] = R"(#version 310 es +in vec4 vertex_in; +out vec4 vertex_out[3]; +void main() +{ + gl_Position = vertex_in; + vertex_out[0] = vec4(1.0, 0.0, 0.0, 1.0); + vertex_out[1] = vec4(0.0, 1.0, 0.0, 1.0); + vertex_out[2] = vec4(0.0, 0.0, 1.0, 1.0); +})"; - const std::string &geometryShader = - R"(#version 310 es - #extension GL_EXT_geometry_shader : require - layout (invocations = 3, triangles) in; - layout (points, max_vertices = 3) out; - in vec4 vertex_out[]; - out vec4 geometry_color; - void main() - { - gl_Position = gl_in[0].gl_Position; - geometry_color = vertex_out[0]; - EmitVertex(); - })"; + constexpr char kGS[] = R"(#version 310 es +#extension GL_EXT_geometry_shader : require +layout (invocations = 3, triangles) in; +layout (points, max_vertices = 3) out; +in vec4 vertex_out[]; +out vec4 geometry_color; +void main() +{ + gl_Position = gl_in[0].gl_Position; + geometry_color = vertex_out[0]; + EmitVertex(); +})"; - const std::string &fragmentShader = - R"(#version 310 es - precision mediump float; - in vec4 geometry_color; - layout (location = 0) out vec4 output_color; - void main() - { - output_color = geometry_color; - })"; + constexpr char kFS[] = R"(#version 310 es +precision mediump float; +in vec4 geometry_color; +layout (location = 0) out vec4 output_color; +void main() +{ + output_color = geometry_color; +})"; - GLuint program = CompileProgramWithGS(vertexShader, geometryShader, fragmentShader); + GLuint program = CompileProgramWithGS(kVS, kGS, kFS); EXPECT_EQ(0u, program); EXPECT_GL_NO_ERROR(); @@ -290,44 +286,41 @@ TEST_P(GeometryShaderTest, UniformMismatchBetweenGeometryAndFragmentShader) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader")); - const std::string &vertexShader = - R"(#version 310 es - uniform highp vec4 uniform_value_vert; - in vec4 vertex_in; - out vec4 vertex_out; - void main() - { - gl_Position = vertex_in; - vertex_out = uniform_value_vert; - })"; + constexpr char kVS[] = R"(#version 310 es +uniform highp vec4 uniform_value_vert; +in vec4 vertex_in; +out vec4 vertex_out; +void main() +{ + gl_Position = vertex_in; + vertex_out = uniform_value_vert; +})"; - const std::string &geometryShader = - R"(#version 310 es - #extension GL_EXT_geometry_shader : require - uniform vec4 uniform_value; - layout (invocations = 3, triangles) in; - layout (points, max_vertices = 3) out; - in vec4 vertex_out[]; - out vec4 geometry_color; - void main() - { - gl_Position = gl_in[0].gl_Position; - geometry_color = vertex_out[0] + uniform_value; - EmitVertex(); - })"; + constexpr char kGS[] = R"(#version 310 es +#extension GL_EXT_geometry_shader : require +uniform vec4 uniform_value; +layout (invocations = 3, triangles) in; +layout (points, max_vertices = 3) out; +in vec4 vertex_out[]; +out vec4 geometry_color; +void main() +{ + gl_Position = gl_in[0].gl_Position; + geometry_color = vertex_out[0] + uniform_value; + EmitVertex(); +})"; - const std::string &fragmentShader = - R"(#version 310 es - precision highp float; - uniform float uniform_value; - in vec4 geometry_color; - layout (location = 0) out vec4 output_color; - void main() - { - output_color = vec4(geometry_color.rgb, uniform_value); - })"; + constexpr char kFS[] = R"(#version 310 es +precision highp float; +uniform float uniform_value; +in vec4 geometry_color; +layout (location = 0) out vec4 output_color; +void main() +{ + output_color = vec4(geometry_color.rgb, uniform_value); +})"; - GLuint program = CompileProgramWithGS(vertexShader, geometryShader, fragmentShader); + GLuint program = CompileProgramWithGS(kVS, kGS, kFS); EXPECT_EQ(0u, program); EXPECT_GL_NO_ERROR(); @@ -365,8 +358,8 @@ TEST_P(GeometryShaderTest, TooManyUniformBlocks) stream << " EmitVertex();\n" "}\n"; - GLuint program = - CompileProgramWithGS(essl31_shaders::vs::Simple(), stream.str(), essl31_shaders::fs::Red()); + GLuint program = CompileProgramWithGS(essl31_shaders::vs::Simple(), stream.str().c_str(), + essl31_shaders::fs::Red()); EXPECT_EQ(0u, program); EXPECT_GL_NO_ERROR(); @@ -404,8 +397,8 @@ TEST_P(GeometryShaderTest, TooManyShaderStorageBlocks) stream << " EmitVertex();\n" "}\n"; - GLuint program = - CompileProgramWithGS(essl31_shaders::vs::Simple(), stream.str(), essl31_shaders::fs::Red()); + GLuint program = CompileProgramWithGS(essl31_shaders::vs::Simple(), stream.str().c_str(), + essl31_shaders::fs::Red()); EXPECT_EQ(0u, program); EXPECT_GL_NO_ERROR(); @@ -417,38 +410,36 @@ TEST_P(GeometryShaderTest, UniformBlockMismatchBetweenVertexAndGeometryShader) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader")); - const std::string &vertexShader = - R"(#version 310 es - uniform ubo - { - vec4 uniform_value_vert; - } block0; - in vec4 vertex_in; - out vec4 vertex_out; - void main() - { - gl_Position = vertex_in; - vertex_out = block0.uniform_value_vert; - })"; + constexpr char kVS[] = R"(#version 310 es +uniform ubo +{ + vec4 uniform_value_vert; +} block0; +in vec4 vertex_in; +out vec4 vertex_out; +void main() +{ + gl_Position = vertex_in; + vertex_out = block0.uniform_value_vert; +})"; - const std::string &geometryShader = - R"(#version 310 es - #extension GL_EXT_geometry_shader : require - uniform ubo - { - vec4 uniform_value_geom; - } block0; - layout (triangles) in; - layout (points, max_vertices = 1) out; - in vec4 vertex_out[]; - void main() - { - gl_Position = gl_in[0].gl_Position + vertex_out[0]; - gl_Position += block0.uniform_value_geom; - EmitVertex(); - })"; + constexpr char kGS[] = R"(#version 310 es +#extension GL_EXT_geometry_shader : require +uniform ubo +{ + vec4 uniform_value_geom; +} block0; +layout (triangles) in; +layout (points, max_vertices = 1) out; +in vec4 vertex_out[]; +void main() +{ + gl_Position = gl_in[0].gl_Position + vertex_out[0]; + gl_Position += block0.uniform_value_geom; + EmitVertex(); +})"; - GLuint program = CompileProgramWithGS(vertexShader, geometryShader, essl31_shaders::fs::Red()); + GLuint program = CompileProgramWithGS(kVS, kGS, essl31_shaders::fs::Red()); EXPECT_EQ(0u, program); EXPECT_GL_NO_ERROR(); @@ -474,36 +465,33 @@ TEST_P(GeometryShaderTest, ShaderStorageBlockMismatchBetweenGeometryAndFragmentS // [OpenGL ES 3.1] Table 20.44 ANGLE_SKIP_TEST_IF(maxFragmentShaderStorageBlocks == 0); - const std::string &geometryShader = - R"(#version 310 es - #extension GL_EXT_geometry_shader : require - buffer ssbo - { - vec4 ssbo_value; - } block0; - layout (triangles) in; - layout (points, max_vertices = 1) out; - void main() - { - gl_Position = gl_in[0].gl_Position + block0.ssbo_value; - EmitVertex(); - })"; + constexpr char kGS[] = R"(#version 310 es +#extension GL_EXT_geometry_shader : require +buffer ssbo +{ + vec4 ssbo_value; +} block0; +layout (triangles) in; +layout (points, max_vertices = 1) out; +void main() +{ + gl_Position = gl_in[0].gl_Position + block0.ssbo_value; + EmitVertex(); +})"; - const std::string &fragmentShader = - R"(#version 310 es - precision highp float; - buffer ssbo - { - vec3 ssbo_value; - } block0; - layout (location = 0) out vec4 output_color; - void main() - { - output_color = vec4(block0.ssbo_value, 1); - })"; + constexpr char kFS[] = R"(#version 310 es +precision highp float; +buffer ssbo +{ + vec3 ssbo_value; +} block0; +layout (location = 0) out vec4 output_color; +void main() +{ + output_color = vec4(block0.ssbo_value, 1); +})"; - GLuint program = - CompileProgramWithGS(essl31_shaders::vs::Simple(), geometryShader, fragmentShader); + GLuint program = CompileProgramWithGS(essl31_shaders::vs::Simple(), kGS, kFS); EXPECT_EQ(0u, program); EXPECT_GL_NO_ERROR(); @@ -515,17 +503,16 @@ TEST_P(GeometryShaderTest, ReferencedByGeometryShaderWithoutExtensionEnabled) { ANGLE_SKIP_TEST_IF(extensionEnabled("GL_EXT_geometry_shader")); - const std::string &fragmentShader = - R"(#version 310 es - precision highp float; - uniform vec4 color; - layout(location = 0) out vec4 oColor; - void main() - { - oColor = color; - })"; + constexpr char kFS[] = R"(#version 310 es +precision highp float; +uniform vec4 color; +layout(location = 0) out vec4 oColor; +void main() +{ + oColor = color; +})"; - ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS); const GLuint index = glGetProgramResourceIndex(program, GL_UNIFORM, "color"); ASSERT_GL_NO_ERROR(); @@ -547,49 +534,46 @@ TEST_P(GeometryShaderTest, ReferencedByGeometryShader) { ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_geometry_shader")); - const std::string &vertexShader = - R"(#version 310 es - precision highp float; - layout(location = 0) in highp vec4 position; - void main() - { - gl_Position = position; - })"; + constexpr char kVS[] = R"(#version 310 es +precision highp float; +layout(location = 0) in highp vec4 position; +void main() +{ + gl_Position = position; +})"; - const std::string &geometryShader = - R"(#version 310 es - #extension GL_EXT_geometry_shader : require - layout (binding = 3) uniform ubo0 - { - vec4 ubo0_location; - } block0; - layout (binding = 4) uniform ubo1 - { - vec4 ubo1_location; - } block1; - uniform vec4 u_color; - layout (triangles) in; - layout (points, max_vertices = 1) out; - out vec4 gs_out; - void main() - { - gl_Position = gl_in[0].gl_Position; - gl_Position += block0.ubo0_location + block1.ubo1_location; - gs_out = u_color; - EmitVertex(); - })"; + constexpr char kGS[] = R"(#version 310 es +#extension GL_EXT_geometry_shader : require +layout (binding = 3) uniform ubo0 +{ + vec4 ubo0_location; +} block0; +layout (binding = 4) uniform ubo1 +{ + vec4 ubo1_location; +} block1; +uniform vec4 u_color; +layout (triangles) in; +layout (points, max_vertices = 1) out; +out vec4 gs_out; +void main() +{ + gl_Position = gl_in[0].gl_Position; + gl_Position += block0.ubo0_location + block1.ubo1_location; + gs_out = u_color; + EmitVertex(); +})"; - const std::string &fragmentShader = - R"(#version 310 es - precision highp float; - in vec4 gs_out; - layout(location = 0) out vec4 oColor; - void main() - { - oColor = gs_out; - })"; + constexpr char kFS[] = R"(#version 310 es +precision highp float; +in vec4 gs_out; +layout(location = 0) out vec4 oColor; +void main() +{ + oColor = gs_out; +})"; - ANGLE_GL_PROGRAM_WITH_GS(program, vertexShader, geometryShader, fragmentShader); + ANGLE_GL_PROGRAM_WITH_GS(program, kVS, kGS, kFS); constexpr GLenum kProps[] = {GL_REFERENCED_BY_GEOMETRY_SHADER_EXT}; constexpr GLsizei kPropCount = static_cast(ArraySize(kProps)); @@ -629,25 +613,23 @@ TEST_P(GeometryShaderTest, ReferencedByGeometryShader) // [EXT_geometry_shader] Table 20.43gs if (maxGeometryShaderStorageBlocks > 0) { - const std::string &geometryShaderWithSSBO = - R"(#version 310 es - #extension GL_EXT_geometry_shader : require - layout (binding = 2) buffer ssbo - { - vec4 ssbo_value; - } block0; - layout (triangles) in; - layout (points, max_vertices = 1) out; - out vec4 gs_out; - void main() - { - gl_Position = gl_in[0].gl_Position + block0.ssbo_value; - gs_out = block0.ssbo_value; - EmitVertex(); - })"; + constexpr char kGSWithSSBO[] = R"(#version 310 es +#extension GL_EXT_geometry_shader : require +layout (binding = 2) buffer ssbo +{ + vec4 ssbo_value; +} block0; +layout (triangles) in; +layout (points, max_vertices = 1) out; +out vec4 gs_out; +void main() +{ + gl_Position = gl_in[0].gl_Position + block0.ssbo_value; + gs_out = block0.ssbo_value; + EmitVertex(); +})"; - ANGLE_GL_PROGRAM_WITH_GS(programWithSSBO, vertexShader, geometryShaderWithSSBO, - fragmentShader); + ANGLE_GL_PROGRAM_WITH_GS(programWithSSBO, kVS, kGSWithSSBO, kFS); params.fill(0); index = glGetProgramResourceIndex(programWithSSBO, GL_SHADER_STORAGE_BLOCK, "ssbo"); @@ -670,23 +652,21 @@ TEST_P(GeometryShaderTest, ReferencedByGeometryShader) // [EXT_geometry_shader] Table 20.43gs if (maxGeometryAtomicCounterBuffers > 0) { - const std::string &geometryShaderWithAtomicCounters = - R"(#version 310 es - #extension GL_EXT_geometry_shader : require - layout(binding = 1, offset = 0) uniform atomic_uint gs_counter; - layout (triangles) in; - layout (points, max_vertices = 1) out; - out vec4 gs_out; - void main() - { - atomicCounterIncrement(gs_counter); - gl_Position = gl_in[0].gl_Position; - gs_out = vec4(1.0, 0.0, 0.0, 1.0); - EmitVertex(); - })"; + constexpr char kGSWithAtomicCounters[] = R"(#version 310 es +#extension GL_EXT_geometry_shader : require +layout(binding = 1, offset = 0) uniform atomic_uint gs_counter; +layout (triangles) in; +layout (points, max_vertices = 1) out; +out vec4 gs_out; +void main() +{ + atomicCounterIncrement(gs_counter); + gl_Position = gl_in[0].gl_Position; + gs_out = vec4(1.0, 0.0, 0.0, 1.0); + EmitVertex(); +})"; - ANGLE_GL_PROGRAM_WITH_GS(programWithAtomicCounter, vertexShader, - geometryShaderWithAtomicCounters, fragmentShader); + ANGLE_GL_PROGRAM_WITH_GS(programWithAtomicCounter, kVS, kGSWithAtomicCounters, kFS); params.fill(0); index = glGetProgramResourceIndex(programWithAtomicCounter, GL_UNIFORM, "gs_counter"); diff --git a/src/tests/gl_tests/ImageTest.cpp b/src/tests/gl_tests/ImageTest.cpp index 3adbb866b..342f789c5 100644 --- a/src/tests/gl_tests/ImageTest.cpp +++ b/src/tests/gl_tests/ImageTest.cpp @@ -42,7 +42,7 @@ class ImageTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vsSource = + constexpr char kVS[] = "precision highp float;\n" "attribute vec4 position;\n" "varying vec2 texcoord;\n" @@ -53,7 +53,7 @@ class ImageTest : public ANGLETest " texcoord = (position.xy * 0.5) + 0.5;\n" " texcoord.y = 1.0 - texcoord.y;\n" "}\n"; - const std::string vsESSL3Source = + constexpr char kVSESSL3[] = "#version 300 es\n" "precision highp float;\n" "in vec4 position;\n" @@ -66,7 +66,7 @@ class ImageTest : public ANGLETest " texcoord.y = 1.0 - texcoord.y;\n" "}\n"; - const std::string textureFSSource = + constexpr char kTextureFS[] = "precision highp float;\n" "uniform sampler2D tex;\n" "varying vec2 texcoord;\n" @@ -75,7 +75,7 @@ class ImageTest : public ANGLETest "{\n" " gl_FragColor = texture2D(tex, texcoord);\n" "}\n"; - const std::string textureExternalFSSource = + constexpr char kTextureExternalFS[] = "#extension GL_OES_EGL_image_external : require\n" "precision highp float;\n" "uniform samplerExternalOES tex;\n" @@ -85,7 +85,7 @@ class ImageTest : public ANGLETest "{\n" " gl_FragColor = texture2D(tex, texcoord);\n" "}\n"; - const std::string textureExternalESSL3FSSource = + constexpr char kTextureExternalESSL3FS[] = "#version 300 es\n" "#extension GL_OES_EGL_image_external_essl3 : require\n" "precision highp float;\n" @@ -98,7 +98,7 @@ class ImageTest : public ANGLETest " color = texture(tex, texcoord);\n" "}\n"; - mTextureProgram = CompileProgram(vsSource, textureFSSource); + mTextureProgram = CompileProgram(kVS, kTextureFS); if (mTextureProgram == 0) { FAIL() << "shader compilation failed."; @@ -108,7 +108,7 @@ class ImageTest : public ANGLETest if (extensionEnabled("GL_OES_EGL_image_external")) { - mTextureExternalProgram = CompileProgram(vsSource, textureExternalFSSource); + mTextureExternalProgram = CompileProgram(kVS, kTextureExternalFS); ASSERT_NE(0u, mTextureExternalProgram) << "shader compilation failed."; mTextureExternalUniformLocation = glGetUniformLocation(mTextureExternalProgram, "tex"); @@ -116,8 +116,7 @@ class ImageTest : public ANGLETest if (extensionEnabled("GL_OES_EGL_image_external_essl3")) { - mTextureExternalESSL3Program = - CompileProgram(vsESSL3Source, textureExternalESSL3FSSource); + mTextureExternalESSL3Program = CompileProgram(kVSESSL3, kTextureExternalESSL3FS); ASSERT_NE(0u, mTextureExternalESSL3Program) << "shader compilation failed."; mTextureExternalESSL3UniformLocation = diff --git a/src/tests/gl_tests/IncompleteTextureTest.cpp b/src/tests/gl_tests/IncompleteTextureTest.cpp index dec956256..a2b24ed16 100644 --- a/src/tests/gl_tests/IncompleteTextureTest.cpp +++ b/src/tests/gl_tests/IncompleteTextureTest.cpp @@ -28,28 +28,26 @@ class IncompleteTextureTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vertexShaderSource = - R"(precision highp float; - attribute vec4 position; - varying vec2 texcoord; + constexpr char kVS[] = R"(precision highp float; +attribute vec4 position; +varying vec2 texcoord; - void main() - { - gl_Position = position; - texcoord = (position.xy * 0.5) + 0.5; - })"; +void main() +{ + gl_Position = position; + texcoord = (position.xy * 0.5) + 0.5; +})"; - const std::string fragmentShaderSource = - R"(precision highp float; - uniform sampler2D tex; - varying vec2 texcoord; + constexpr char kFS[] = R"(precision highp float; +uniform sampler2D tex; +varying vec2 texcoord; - void main() - { - gl_FragColor = texture2D(tex, texcoord); - })"; +void main() +{ + gl_FragColor = texture2D(tex, texcoord); +})"; - mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); if (mProgram == 0) { FAIL() << "shader compilation failed."; @@ -195,17 +193,16 @@ TEST_P(IncompleteTextureTestES3, UnpackBufferBound) // Tests that the incomplete multisample texture has the correct alpha value. TEST_P(IncompleteTextureTestES31, MultisampleTexture) { - const std::string vertexShader = R"(#version 310 es + constexpr char kVS[] = R"(#version 310 es in vec2 position; out vec2 texCoord; void main() { gl_Position = vec4(position, 0, 1); texCoord = (position * 0.5) + 0.5; -} -)"; +})"; - const std::string fragmentShader = R"(#version 310 es + constexpr char kFS[] = R"(#version 310 es precision mediump float; in vec2 texCoord; out vec4 color; @@ -215,15 +212,14 @@ void main() ivec2 texSize = textureSize(tex); ivec2 texel = ivec2(vec2(texSize) * texCoord); color = texelFetch(tex, texel, 0); -} -)"; +})"; glClearColor(1.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); // The zero texture will be incomplete by default. - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "position", 0.5f); ASSERT_GL_NO_ERROR(); diff --git a/src/tests/gl_tests/IndexBufferOffsetTest.cpp b/src/tests/gl_tests/IndexBufferOffsetTest.cpp index 256a3eb9c..8a1a34871 100644 --- a/src/tests/gl_tests/IndexBufferOffsetTest.cpp +++ b/src/tests/gl_tests/IndexBufferOffsetTest.cpp @@ -28,7 +28,7 @@ class IndexBufferOffsetTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vertexShaderSource = + constexpr char kVS[] = R"(precision highp float; attribute vec2 position; @@ -37,7 +37,7 @@ class IndexBufferOffsetTest : public ANGLETest gl_Position = vec4(position, 0.0, 1.0); })"; - const std::string fragmentShaderSource = + constexpr char kFS[] = R"(precision highp float; uniform vec4 color; @@ -46,7 +46,7 @@ class IndexBufferOffsetTest : public ANGLETest gl_FragColor = color; })"; - mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); mColorUniformLocation = glGetUniformLocation(mProgram, "color"); diff --git a/src/tests/gl_tests/IndexedPointsTest.cpp b/src/tests/gl_tests/IndexedPointsTest.cpp index 8e45f7b59..d59c14e9c 100644 --- a/src/tests/gl_tests/IndexedPointsTest.cpp +++ b/src/tests/gl_tests/IndexedPointsTest.cpp @@ -27,52 +27,47 @@ class IndexedPointsTest : public ANGLETest float getIndexPositionY(size_t idx) { return (idx == 2 || idx == 3) ? -0.5f : 0.5f; } - virtual void SetUp() + void SetUp() override { ANGLETest::SetUp(); - const std::string vertexShaderSource = - R"(precision highp float; - attribute vec2 position; + constexpr char kVS[] = R"(precision highp float; +attribute vec2 position; - void main() { - gl_PointSize = 5.0; - gl_Position = vec4(position, 0.0, 1.0); - })"; +void main() { + gl_PointSize = 5.0; + gl_Position = vec4(position, 0.0, 1.0); +})"; - const std::string fragmentShaderSource = - R"(precision highp float; + constexpr char kFS[] = R"(precision highp float; +void main() +{ + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); +})"; - void main() - { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - })"; - - mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); - const std::string vertexShaderSource2 = - R"(precision highp float; - attribute vec2 position; - attribute vec4 color; - varying vec4 vcolor; + constexpr char kVS2[] = R"(precision highp float; +attribute vec2 position; +attribute vec4 color; +varying vec4 vcolor; - void main() { - gl_PointSize = 5.0; - gl_Position = vec4(position, 0.0, 1.0); - vcolor = color; - })"; +void main() { + gl_PointSize = 5.0; + gl_Position = vec4(position, 0.0, 1.0); + vcolor = color; +})"; - const std::string fragmentShaderSource2 = - R"(precision highp float; - varying vec4 vcolor; + constexpr char kFS2[] = R"(precision highp float; +varying vec4 vcolor; - void main() - { - gl_FragColor = vec4(vcolor.xyz, 1.0); - })"; +void main() +{ + gl_FragColor = vec4(vcolor.xyz, 1.0); +})"; - mVertexWithColorBufferProgram = CompileProgram(vertexShaderSource2, fragmentShaderSource2); + mVertexWithColorBufferProgram = CompileProgram(kVS2, kFS2); ASSERT_NE(0u, mVertexWithColorBufferProgram); // Construct a vertex buffer of position values and color values @@ -105,7 +100,7 @@ class IndexedPointsTest : public ANGLETest glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW); } - virtual void TearDown() + void TearDown() override { glDeleteBuffers(1, &mVertexBuffer); glDeleteBuffers(1, &mIndexBuffer); diff --git a/src/tests/gl_tests/InstancingTest.cpp b/src/tests/gl_tests/InstancingTest.cpp index 8a6510277..0a3f9742e 100644 --- a/src/tests/gl_tests/InstancingTest.cpp +++ b/src/tests/gl_tests/InstancingTest.cpp @@ -53,13 +53,15 @@ class InstancingTest : public ANGLETest )"; // attrib 0 is instanced - mProgram0 = CompileProgram(inst + pos + main, essl1_shaders::fs::Red()); + const std::string inst0 = inst + pos + main; + mProgram0 = CompileProgram(inst0.c_str(), essl1_shaders::fs::Red()); ASSERT_NE(0u, mProgram0); ASSERT_EQ(0, glGetAttribLocation(mProgram0, "a_instance")); ASSERT_EQ(1, glGetAttribLocation(mProgram0, "a_position")); // attrib 1 is instanced - mProgram1 = CompileProgram(pos + inst + main, essl1_shaders::fs::Red()); + const std::string inst1 = pos + inst + main; + mProgram1 = CompileProgram(inst1.c_str(), essl1_shaders::fs::Red()); ASSERT_NE(0u, mProgram1); ASSERT_EQ(1, glGetAttribLocation(mProgram1, "a_instance")); ASSERT_EQ(0, glGetAttribLocation(mProgram1, "a_position")); @@ -360,7 +362,7 @@ TEST_P(InstancingTestES31, UpdateAttribBindingByVertexAttribDivisor) // Verify that a large divisor that also changes doesn't cause issues and renders correctly. TEST_P(InstancingTestES3, LargeDivisor) { - const std::string &vs = R"(#version 300 es + constexpr char kVS[] = R"(#version 300 es layout(location = 0) in vec4 a_position; layout(location = 1) in vec4 a_color; out vec4 v_color; @@ -371,7 +373,7 @@ void main() v_color = a_color; })"; - const std::string &fs = R"(#version 300 es + constexpr char kFS[] = R"(#version 300 es precision highp float; in vec4 v_color; out vec4 my_FragColor; @@ -380,7 +382,7 @@ void main() my_FragColor = v_color; })"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); glClearColor(0.0f, 0.0f, 1.0f, 1.0f); diff --git a/src/tests/gl_tests/LinkAndRelinkTest.cpp b/src/tests/gl_tests/LinkAndRelinkTest.cpp index 41e8baa38..61fcb435f 100644 --- a/src/tests/gl_tests/LinkAndRelinkTest.cpp +++ b/src/tests/gl_tests/LinkAndRelinkTest.cpp @@ -68,20 +68,13 @@ TEST_P(LinkAndRelinkTest, RenderingProgramFailsWithProgramInstalled) // Install a render program in current GL state via UseProgram, then render. // It should succeed. - const std::string vsSource = - R"(void main() - { - })"; - - const std::string fsSource = - R"(void main() - { - })"; + constexpr char kVS[] = "void main() {}"; + constexpr char kFS[] = "void main() {}"; GLuint program = glCreateProgram(); - GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); + GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); EXPECT_NE(0u, vs); EXPECT_NE(0u, fs); @@ -195,7 +188,7 @@ TEST_P(LinkAndRelinkTestES31, ComputeProgramFailsWithProgramInstalled) { // Install a compute program in the GL state via UseProgram, then dispatch // compute. It should succeed. - const std::string csSource = + constexpr char kCS[] = R"(#version 310 es layout(local_size_x=1) in; void main() @@ -204,7 +197,7 @@ TEST_P(LinkAndRelinkTestES31, ComputeProgramFailsWithProgramInstalled) GLuint program = glCreateProgram(); - GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource); + GLuint cs = CompileShader(GL_COMPUTE_SHADER, kCS); EXPECT_NE(0u, cs); glAttachShader(program, cs); @@ -290,16 +283,15 @@ TEST_P(LinkAndRelinkTestES31, ComputeProgramFailsWithProgramInstalled) // then dispatching compute will fail, but starting rendering can succeed. TEST_P(LinkAndRelinkTestES31, RelinkProgramSucceedsFromComputeToRendering) { - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1) in; - void main() - { - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1) in; +void main() +{ +})"; GLuint program = glCreateProgram(); - GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource); + GLuint cs = CompileShader(GL_COMPUTE_SHADER, kCS); EXPECT_NE(0u, cs); glAttachShader(program, cs); @@ -321,18 +313,11 @@ TEST_P(LinkAndRelinkTestES31, RelinkProgramSucceedsFromComputeToRendering) glDrawArrays(GL_POINTS, 0, 1); EXPECT_GL_ERROR(GL_INVALID_OPERATION); - const std::string vsSource = - R"(void main() - { - })"; + constexpr char kVS[] = "void main() {}"; + constexpr char kFS[] = "void main() {}"; - const std::string fsSource = - R"(void main() - { - })"; - - GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); + GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); EXPECT_NE(0u, vs); EXPECT_NE(0u, fs); @@ -363,20 +348,13 @@ TEST_P(LinkAndRelinkTestES31, RelinkProgramSucceedsFromComputeToRendering) // then starting rendering will fail, but dispatching compute can succeed. TEST_P(LinkAndRelinkTestES31, RelinkProgramSucceedsFromRenderingToCompute) { - const std::string vsSource = - R"(void main() - { - })"; - - const std::string fsSource = - R"(void main() - { - })"; + constexpr char kVS[] = "void main() {}"; + constexpr char kFS[] = "void main() {}"; GLuint program = glCreateProgram(); - GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); + GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); EXPECT_NE(0u, vs); EXPECT_NE(0u, fs); @@ -404,14 +382,13 @@ TEST_P(LinkAndRelinkTestES31, RelinkProgramSucceedsFromRenderingToCompute) glDispatchCompute(8, 4, 2); EXPECT_GL_ERROR(GL_INVALID_OPERATION); - const std::string csSource = - R"(#version 310 es - layout(local_size_x=1) in; - void main() - { - })"; + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1) in; +void main() +{ +})"; - GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource); + GLuint cs = CompileShader(GL_COMPUTE_SHADER, kCS); EXPECT_NE(0u, cs); glAttachShader(program, cs); diff --git a/src/tests/gl_tests/MaxTextureSizeTest.cpp b/src/tests/gl_tests/MaxTextureSizeTest.cpp index 4254c01ea..502d50d9c 100644 --- a/src/tests/gl_tests/MaxTextureSizeTest.cpp +++ b/src/tests/gl_tests/MaxTextureSizeTest.cpp @@ -25,37 +25,33 @@ class MaxTextureSizeTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vsSource = - R"(precision highp float; - attribute vec4 position; - varying vec2 texcoord; + constexpr char kVS[] = R"(precision highp float; +attribute vec4 position; +varying vec2 texcoord; - void main() - { - gl_Position = position; - texcoord = (position.xy * 0.5) + 0.5; - })"; +void main() +{ + gl_Position = position; + texcoord = (position.xy * 0.5) + 0.5; +})"; - const std::string textureFSSource = - R"(precision highp float; - uniform sampler2D tex; - varying vec2 texcoord; + constexpr char kTextureFS[] = R"(precision highp float; +uniform sampler2D tex; +varying vec2 texcoord; - void main() - { - gl_FragColor = texture2D(tex, texcoord); - })"; +void main() +{ + gl_FragColor = texture2D(tex, texcoord); +})"; - const std::string blueFSSource = - R"(precision highp float; + constexpr char kBlueFS[] = R"(precision highp float; +void main() +{ + gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); +})"; - void main() - { - gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); - })"; - - mTextureProgram = CompileProgram(vsSource, textureFSSource); - mBlueProgram = CompileProgram(vsSource, blueFSSource); + mTextureProgram = CompileProgram(kVS, kTextureFS); + mBlueProgram = CompileProgram(kVS, kBlueFS); if (mTextureProgram == 0 || mBlueProgram == 0) { FAIL() << "shader compilation failed."; diff --git a/src/tests/gl_tests/MipmapTest.cpp b/src/tests/gl_tests/MipmapTest.cpp index 09562767d..0a9e7c5d8 100644 --- a/src/tests/gl_tests/MipmapTest.cpp +++ b/src/tests/gl_tests/MipmapTest.cpp @@ -75,56 +75,51 @@ class MipmapTest : public BaseMipmapTest void setUp2DProgram() { // Vertex Shader source - const std::string vs = - R"(attribute vec4 position; - varying vec2 vTexCoord; + constexpr char kVS[] = R"(attribute vec4 position; +varying vec2 vTexCoord; - void main() - { - gl_Position = position; - vTexCoord = (position.xy * 0.5) + 0.5; - })"; +void main() +{ + gl_Position = position; + vTexCoord = (position.xy * 0.5) + 0.5; +})"; // Fragment Shader source - const std::string fs = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; +uniform sampler2D uTexture; +varying vec2 vTexCoord; - uniform sampler2D uTexture; - varying vec2 vTexCoord; +void main() +{ + gl_FragColor = texture2D(uTexture, vTexCoord); +})"; - void main() - { - gl_FragColor = texture2D(uTexture, vTexCoord); - })"; - - m2DProgram = CompileProgram(vs, fs); + m2DProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, m2DProgram); } void setUpCubeProgram() { // A simple vertex shader for the texture cube - const std::string cubeVS = - R"(attribute vec4 position; - varying vec4 vPosition; - void main() - { - gl_Position = position; - vPosition = position; - })"; + constexpr char kVS[] = R"(attribute vec4 position; +varying vec4 vPosition; +void main() +{ + gl_Position = position; + vPosition = position; +})"; // A very simple fragment shader to sample from the negative-Y face of a texture cube. - const std::string cubeFS = - R"(precision mediump float; - uniform samplerCube uTexture; - varying vec4 vPosition; + constexpr char kFS[] = R"(precision mediump float; +uniform samplerCube uTexture; +varying vec4 vPosition; - void main() - { - gl_FragColor = textureCube(uTexture, vec3(vPosition.x, -1, vPosition.y)); - })"; +void main() +{ + gl_FragColor = textureCube(uTexture, vec3(vPosition.x, -1, vPosition.y)); +})"; - mCubeProgram = CompileProgram(cubeVS, cubeFS); + mCubeProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mCubeProgram); } @@ -251,40 +246,39 @@ class MipmapTestES3 : public BaseMipmapTest setConfigAlphaBits(8); } - std::string vertexShaderSource() + const char *vertexShaderSource() { // Don't put "#version ..." on its own line. See [cpp]p1: // "If there are sequences of preprocessing tokens within the list of arguments that // would otherwise act as preprocessing directives, the behavior is undefined" return R"(#version 300 es - precision highp float; - in vec4 position; - out vec2 texcoord; +precision highp float; +in vec4 position; +out vec2 texcoord; - void main() - { - gl_Position = vec4(position.xy, 0.0, 1.0); - texcoord = (position.xy * 0.5) + 0.5; - })"; +void main() +{ + gl_Position = vec4(position.xy, 0.0, 1.0); + texcoord = (position.xy * 0.5) + 0.5; +})"; } void setUpArrayProgram() { - const std::string fragmentShaderSourceArray = - R"(#version 300 es - precision highp float; - uniform highp sampler2DArray tex; - uniform int slice; - in vec2 texcoord; - out vec4 out_FragColor; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +uniform highp sampler2DArray tex; +uniform int slice; +in vec2 texcoord; +out vec4 out_FragColor; - void main() - { - out_FragColor = texture(tex, vec3(texcoord, float(slice))); - })"; +void main() +{ + out_FragColor = texture(tex, vec3(texcoord, float(slice))); +})"; - mArrayProgram = CompileProgram(vertexShaderSource(), fragmentShaderSourceArray); + mArrayProgram = CompileProgram(vertexShaderSource(), kFS); if (mArrayProgram == 0) { FAIL() << "shader compilation failed."; @@ -300,21 +294,20 @@ class MipmapTestES3 : public BaseMipmapTest void setUp3DProgram() { - const std::string fragmentShaderSource3D = - R"(#version 300 es - precision highp float; - uniform highp sampler3D tex; - uniform float slice; - uniform float lod; - in vec2 texcoord; - out vec4 out_FragColor; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +uniform highp sampler3D tex; +uniform float slice; +uniform float lod; +in vec2 texcoord; +out vec4 out_FragColor; - void main() - { - out_FragColor = textureLod(tex, vec3(texcoord, slice), lod); - })"; +void main() +{ + out_FragColor = textureLod(tex, vec3(texcoord, slice), lod); +})"; - m3DProgram = CompileProgram(vertexShaderSource(), fragmentShaderSource3D); + m3DProgram = CompileProgram(vertexShaderSource(), kFS); if (m3DProgram == 0) { FAIL() << "shader compilation failed."; @@ -334,19 +327,18 @@ class MipmapTestES3 : public BaseMipmapTest void setUp2DProgram() { - const std::string fragmentShaderSource2D = - R"(#version 300 es - precision highp float; - uniform highp sampler2D tex; - in vec2 texcoord; - out vec4 out_FragColor; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +uniform highp sampler2D tex; +in vec2 texcoord; +out vec4 out_FragColor; - void main() - { - out_FragColor = texture(tex, texcoord); - })"; +void main() +{ + out_FragColor = texture(tex, texcoord); +})"; - m2DProgram = CompileProgram(vertexShaderSource(), fragmentShaderSource2D); + m2DProgram = CompileProgram(vertexShaderSource(), kFS); ASSERT_NE(0u, m2DProgram); ASSERT_GL_NO_ERROR(); @@ -355,19 +347,18 @@ class MipmapTestES3 : public BaseMipmapTest void setUpCubeProgram() { // A very simple fragment shader to sample from the negative-Y face of a texture cube. - const std::string cubeFS = - R"(#version 300 es - precision mediump float; - uniform samplerCube uTexture; - in vec2 texcoord; - out vec4 out_FragColor; + constexpr char kFS[] = R"(#version 300 es +precision mediump float; +uniform samplerCube uTexture; +in vec2 texcoord; +out vec4 out_FragColor; - void main() - { - out_FragColor = texture(uTexture, vec3(texcoord.x, -1, texcoord.y)); - })"; +void main() +{ + out_FragColor = texture(uTexture, vec3(texcoord.x, -1, texcoord.y)); +})"; - mCubeProgram = CompileProgram(vertexShaderSource(), cubeFS); + mCubeProgram = CompileProgram(vertexShaderSource(), kFS); ASSERT_NE(0u, mCubeProgram); ASSERT_GL_NO_ERROR(); diff --git a/src/tests/gl_tests/MultiviewDrawTest.cpp b/src/tests/gl_tests/MultiviewDrawTest.cpp index ef54bc813..c753e681f 100644 --- a/src/tests/gl_tests/MultiviewDrawTest.cpp +++ b/src/tests/gl_tests/MultiviewDrawTest.cpp @@ -531,7 +531,7 @@ TEST_P(MultiviewDrawValidationTest, IndirectDraw) const GLint viewportOffsets[4] = {0, 0, 2, 0}; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -557,13 +557,13 @@ TEST_P(MultiviewDrawValidationTest, IndirectDraw) // Check for a GL_INVALID_OPERATION error with the framebuffer having 2 views. { - const std::string &vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" "void main()\n" "{}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex2D, 0, @@ -578,13 +578,13 @@ TEST_P(MultiviewDrawValidationTest, IndirectDraw) // Check that no errors are generated if the number of views is 1. { - const std::string &vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 1) in;\n" "void main()\n" "{}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); glFramebufferTextureMultiviewSideBySideANGLE(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex2D, 0, @@ -611,19 +611,19 @@ TEST_P(MultiviewDrawValidationTest, NumViewsMismatch) const GLint viewportOffsets[4] = {0, 0, 2, 0}; - const std::string &vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" "void main()\n" "{}\n"; - const std::string &fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" "void main()\n" "{}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLVertexArray vao; @@ -674,16 +674,16 @@ TEST_P(MultiviewDrawValidationTest, NumViewsMismatchForNonMultiviewProgram) return; } - const std::string &vsSourceNoMultiview = + constexpr char kVS[] = "#version 300 es\n" "void main()\n" "{}\n"; - const std::string &fsSourceNoMultiview = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "void main()\n" "{}\n"; - ANGLE_GL_PROGRAM(programNoMultiview, vsSourceNoMultiview, fsSourceNoMultiview); + ANGLE_GL_PROGRAM(programNoMultiview, kVS, kFS); glUseProgram(programNoMultiview); GLVertexArray vao; @@ -721,22 +721,21 @@ TEST_P(MultiviewDrawValidationTest, ActiveTransformFeedback) const GLint viewportOffsets[4] = {0, 0, 2, 0}; - const std::string &vsSource = - R"(#version 300 es - out float tfVarying; - void main() - { - tfVarying = 1.0; - })"; - const std::string &fsSource = - R"(#version 300 es - precision mediump float; - void main() - {})"; + constexpr char kVS[] = R"(#version 300 es +out float tfVarying; +void main() +{ + tfVarying = 1.0; +})"; + + constexpr char kFS[] = R"(#version 300 es +precision mediump float; +void main() +{})"; std::vector tfVaryings; tfVaryings.emplace_back("tfVarying"); - ANGLE_GL_PROGRAM_TRANSFORM_FEEDBACK(singleViewProgram, vsSource, fsSource, tfVaryings, + ANGLE_GL_PROGRAM_TRANSFORM_FEEDBACK(singleViewProgram, kVS, kFS, tfVaryings, GL_SEPARATE_ATTRIBS); std::vector dualViewTFVaryings; @@ -840,16 +839,16 @@ TEST_P(MultiviewDrawValidationTest, ActiveTimeElapsedQuery) ANGLE_GL_PROGRAM(dualViewProgram, kDualViewVSSource, kDualViewFSSource); const GLint viewportOffsets[4] = {0, 0, 2, 0}; - const std::string &vsSource = + constexpr char kVS[] = "#version 300 es\n" "void main()\n" "{}\n"; - const std::string &fsSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "void main()\n" "{}\n"; - ANGLE_GL_PROGRAM(singleViewProgram, vsSource, fsSource); + ANGLE_GL_PROGRAM(singleViewProgram, kVS, kFS); glUseProgram(singleViewProgram); GLVertexArray vao; @@ -963,7 +962,7 @@ TEST_P(MultiviewRenderTest, DrawArraysFourViews) return; } - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 4) in;\n" @@ -982,7 +981,7 @@ TEST_P(MultiviewRenderTest, DrawArraysFourViews) " gl_Position.yzw = vPosition.yzw;\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -993,7 +992,7 @@ TEST_P(MultiviewRenderTest, DrawArraysFourViews) "}\n"; updateFBOs(4, 1, 4); - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "vPosition", 0.0f, 1.0f, true); ASSERT_GL_NO_ERROR(); @@ -1024,7 +1023,7 @@ TEST_P(MultiviewRenderTest, DrawArraysInstanced) return; } - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1041,7 +1040,7 @@ TEST_P(MultiviewRenderTest, DrawArraysInstanced) " gl_Position.yzw = p.yzw;\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1055,7 +1054,7 @@ TEST_P(MultiviewRenderTest, DrawArraysInstanced) const int kViewHeight = 2; const int kNumViews = 2; updateFBOs(kViewWidth, kViewHeight, kNumViews); - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuadInstanced(program, "vPosition", 0.0f, 1.0f, true, 2u); ASSERT_GL_NO_ERROR(); @@ -1100,7 +1099,7 @@ TEST_P(MultiviewRenderTest, AttribDivisor) ignoreD3D11SDKLayersWarnings(); } - const std::string &vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1115,7 +1114,7 @@ TEST_P(MultiviewRenderTest, AttribDivisor) " gl_Position.yzw = p.yzw;\n" "}\n"; - const std::string &fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1129,7 +1128,7 @@ TEST_P(MultiviewRenderTest, AttribDivisor) const int kViewHeight = 4; const int kNumViews = 2; updateFBOs(kViewWidth, kViewHeight, kNumViews); - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); GLBuffer xOffsetVBO; glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO); @@ -1183,7 +1182,7 @@ TEST_P(MultiviewRenderTest, DivisorOrderOfOperation) updateFBOs(1, 1, 2); // Create multiview program. - const std::string &vs = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1196,7 +1195,7 @@ TEST_P(MultiviewRenderTest, DivisorOrderOfOperation) " gl_Position = p;\n" "}\n"; - const std::string &fs = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1206,9 +1205,9 @@ TEST_P(MultiviewRenderTest, DivisorOrderOfOperation) " col = vec4(0,1,0,1);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); - const std::string &dummyVS = + constexpr char kDummyVS[] = "#version 300 es\n" "layout(location = 0) in vec2 vPosition;\n" "layout(location = 1) in float offsetX;\n" @@ -1217,7 +1216,7 @@ TEST_P(MultiviewRenderTest, DivisorOrderOfOperation) " gl_Position = vec4(vPosition, 0.0, 1.0);\n" "}\n"; - const std::string &dummyFS = + constexpr char kDummyFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 col;\n" @@ -1226,7 +1225,7 @@ TEST_P(MultiviewRenderTest, DivisorOrderOfOperation) " col = vec4(0,0,0,1);\n" "}\n"; - ANGLE_GL_PROGRAM(dummyProgram, dummyVS, dummyFS); + ANGLE_GL_PROGRAM(dummyProgram, kDummyVS, kDummyFS); GLBuffer xOffsetVBO; glBindBuffer(GL_ARRAY_BUFFER, xOffsetVBO); @@ -1343,7 +1342,7 @@ TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryNothingVisible) ANGLE_SKIP_TEST_IF(!requestMultiviewExtension()); ANGLE_SKIP_TEST_IF(!requestOcclusionQueryExtension()); - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1354,7 +1353,7 @@ TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryNothingVisible) " gl_Position.yzw = vec3(vPosition.yz, 1.);\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1363,7 +1362,7 @@ TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryNothingVisible) "{\n" " col = vec4(1,0,0,0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); updateFBOs(1, 1, 2); GLuint result = drawAndRetrieveOcclusionQueryResult(program); @@ -1378,7 +1377,7 @@ TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyLeftVisible) ANGLE_SKIP_TEST_IF(!requestMultiviewExtension()); ANGLE_SKIP_TEST_IF(!requestOcclusionQueryExtension()); - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1389,7 +1388,7 @@ TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyLeftVisible) " gl_Position.yzw = vec3(vPosition.yz, 1.);\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1398,7 +1397,7 @@ TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyLeftVisible) "{\n" " col = vec4(1,0,0,0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); updateFBOs(1, 1, 2); GLuint result = drawAndRetrieveOcclusionQueryResult(program); @@ -1413,7 +1412,7 @@ TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyRightVisible) ANGLE_SKIP_TEST_IF(!requestMultiviewExtension()); ANGLE_SKIP_TEST_IF(!requestOcclusionQueryExtension()); - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1424,7 +1423,7 @@ TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyRightVisible) " gl_Position.yzw = vec3(vPosition.yz, 1.);\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1433,7 +1432,7 @@ TEST_P(MultiviewOcclusionQueryTest, OcclusionQueryOnlyRightVisible) "{\n" " col = vec4(1,0,0,0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); updateFBOs(1, 1, 2); GLuint result = drawAndRetrieveOcclusionQueryResult(program); @@ -1450,7 +1449,7 @@ TEST_P(MultiviewProgramGenerationTest, SimpleProgram) return; } - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1458,7 +1457,7 @@ TEST_P(MultiviewProgramGenerationTest, SimpleProgram) "{\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1466,7 +1465,7 @@ TEST_P(MultiviewProgramGenerationTest, SimpleProgram) "{\n" "}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); EXPECT_GL_NO_ERROR(); @@ -1481,7 +1480,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInVertexShader) return; } - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1494,7 +1493,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInVertexShader) " }\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1502,7 +1501,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInVertexShader) "{\n" "}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); EXPECT_GL_NO_ERROR(); @@ -1517,7 +1516,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInFragmentShader) return; } - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1525,7 +1524,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInFragmentShader) "{\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1539,7 +1538,7 @@ TEST_P(MultiviewProgramGenerationTest, UseViewIDInFragmentShader) " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); EXPECT_GL_NO_ERROR(); @@ -1556,7 +1555,7 @@ TEST_P(MultiviewRenderPrimitiveTest, Points) // Test failing on P400 graphics card (anglebug.com/2228) ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11() && IsNVIDIA()); - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1567,7 +1566,7 @@ TEST_P(MultiviewRenderPrimitiveTest, Points) " gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1576,7 +1575,7 @@ TEST_P(MultiviewRenderPrimitiveTest, Points) "{\n" " col = vec4(0,1,0,1);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); const int kViewWidth = 4; @@ -1802,7 +1801,7 @@ TEST_P(MultiviewSideBySideRenderTest, NoLeakingFragments) glScissor(0, 0, 1, 1); glEnable(GL_SCISSOR_TEST); - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -1813,7 +1812,7 @@ TEST_P(MultiviewSideBySideRenderTest, NoLeakingFragments) " gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1826,7 +1825,7 @@ TEST_P(MultiviewSideBySideRenderTest, NoLeakingFragments) " col = vec4(0,1,0,1);\n" " }\n" "}\n"; - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); const std::vector &windowCoordinates = {Vector2I(0, 0), Vector2I(2, 0)}; @@ -1883,7 +1882,7 @@ TEST_P(MultiviewRenderTest, ProgramRelinkUpdatesAttribDivisor) const int kViewHeight = 1; const int kNumViews = 2; - const std::string &fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -1916,7 +1915,7 @@ TEST_P(MultiviewRenderTest, ProgramRelinkUpdatesAttribDivisor) }; std::string vsSource = generateVertexShaderSource(kNumViews); - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, vsSource.c_str(), kFS); glUseProgram(program); GLint positionLoc; @@ -1964,9 +1963,9 @@ TEST_P(MultiviewRenderTest, ProgramRelinkUpdatesAttribDivisor) vsSource = generateVertexShaderSource(kNewNumViews); updateFBOs(kViewWidth, kViewHeight, kNewNumViews); - GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); + GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource.c_str()); ASSERT_NE(0u, vs); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); ASSERT_NE(0u, fs); GLint numAttachedShaders = 0; @@ -2078,7 +2077,7 @@ TEST_P(MultiviewRenderTest, SelectColorBasedOnViewIDOVR) return; } - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 3) in;\n" @@ -2088,7 +2087,7 @@ TEST_P(MultiviewRenderTest, SelectColorBasedOnViewIDOVR) " gl_Position = vec4(vPosition, 1.);\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -2107,7 +2106,7 @@ TEST_P(MultiviewRenderTest, SelectColorBasedOnViewIDOVR) "}\n"; updateFBOs(1, 1, 3); - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "vPosition", 0.0f, 1.0f, true); ASSERT_GL_NO_ERROR(); @@ -2127,7 +2126,7 @@ TEST_P(MultiviewLayeredRenderTest, RenderToSubrangeOfLayers) return; } - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -2137,7 +2136,7 @@ TEST_P(MultiviewLayeredRenderTest, RenderToSubrangeOfLayers) " gl_Position = vec4(vPosition, 1.);\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -2148,7 +2147,7 @@ TEST_P(MultiviewLayeredRenderTest, RenderToSubrangeOfLayers) "}\n"; updateFBOs(1, 1, 2, 4, 1); - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "vPosition", 0.0f, 1.0f, true); ASSERT_GL_NO_ERROR(); @@ -2173,7 +2172,7 @@ TEST_P(MultiviewRenderTest, FlatInterpolation) return; } - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -2185,7 +2184,7 @@ TEST_P(MultiviewRenderTest, FlatInterpolation) " oInstanceID = gl_InstanceID;\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -2204,7 +2203,7 @@ TEST_P(MultiviewRenderTest, FlatInterpolation) "}\n"; updateFBOs(1, 1, 2); - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "vPosition", 0.0f, 1.0f, true); ASSERT_GL_NO_ERROR(); @@ -2223,7 +2222,7 @@ TEST_P(MultiviewRenderTest, FlatInterpolation2) return; } - const std::string vsSource = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -2235,7 +2234,7 @@ TEST_P(MultiviewRenderTest, FlatInterpolation2) " flatVarying = int(gl_ViewID_OVR);\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -2251,7 +2250,7 @@ TEST_P(MultiviewRenderTest, FlatInterpolation2) "}\n"; updateFBOs(1, 1, 2); - ANGLE_GL_PROGRAM(program, vsSource, fsSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "vPosition", 0.0f, 1.0f, true); ASSERT_GL_NO_ERROR(); @@ -2273,7 +2272,7 @@ TEST_P(MultiviewSideBySideRenderTest, ViewportOffsetsAppliedBugCoverage) updateFBOs(1, 1, 2); // Create multiview program. - const std::string &vs = + constexpr char kVS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "layout(num_views = 2) in;\n" @@ -2283,7 +2282,7 @@ TEST_P(MultiviewSideBySideRenderTest, ViewportOffsetsAppliedBugCoverage) " gl_Position = vec4(vPosition, 1.0);\n" "}\n"; - const std::string &fs = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -2293,7 +2292,7 @@ TEST_P(MultiviewSideBySideRenderTest, ViewportOffsetsAppliedBugCoverage) " col = vec4(0,1,0,1);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glViewport(0, 0, 1, 1); glScissor(0, 0, 1, 1); diff --git a/src/tests/gl_tests/PBOExtensionTest.cpp b/src/tests/gl_tests/PBOExtensionTest.cpp index baa63a4e8..fa29545cb 100644 --- a/src/tests/gl_tests/PBOExtensionTest.cpp +++ b/src/tests/gl_tests/PBOExtensionTest.cpp @@ -8,6 +8,27 @@ using namespace angle; +namespace +{ +constexpr char kVS[] = R"(attribute vec4 aTest; +attribute vec2 aPosition; +varying vec4 vTest; + +void main() +{ + vTest = aTest; + gl_Position = vec4(aPosition, 0.0, 1.0); + gl_PointSize = 1.0; +})"; + +constexpr char kFS[] = R"(precision mediump float; +varying vec4 vTest; +void main() +{ + gl_FragColor = vTest; +})"; +} // namespace + class PBOExtensionTest : public ANGLETest { protected: @@ -21,7 +42,7 @@ class PBOExtensionTest : public ANGLETest setConfigAlphaBits(8); } - virtual void SetUp() + void SetUp() override { ANGLETest::SetUp(); @@ -33,27 +54,7 @@ class PBOExtensionTest : public ANGLETest GL_STATIC_DRAW); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); - const char *vertexShaderSrc = - R"(attribute vec4 aTest; - attribute vec2 aPosition; - varying vec4 vTest; - - void main() - { - vTest = aTest; - gl_Position = vec4(aPosition, 0.0, 1.0); - gl_PointSize = 1.0; - })"; - - const char *fragmentShaderSrc = - R"(precision mediump float; - varying vec4 vTest; - void main() - { - gl_FragColor = vTest; - })"; - - mProgram = CompileProgram(vertexShaderSrc, fragmentShaderSrc); + mProgram = CompileProgram(kVS, kFS); glGenBuffers(1, &mPositionVBO); glBindBuffer(GL_ARRAY_BUFFER, mPositionVBO); @@ -63,7 +64,7 @@ class PBOExtensionTest : public ANGLETest ASSERT_GL_NO_ERROR(); } - virtual void TearDown() + void TearDown() override { ANGLETest::TearDown(); diff --git a/src/tests/gl_tests/PackUnpackTest.cpp b/src/tests/gl_tests/PackUnpackTest.cpp index e071997ff..b39a0e7bb 100644 --- a/src/tests/gl_tests/PackUnpackTest.cpp +++ b/src/tests/gl_tests/PackUnpackTest.cpp @@ -32,50 +32,47 @@ class PackUnpackTest : public ANGLETest ANGLETest::SetUp(); // Fragment Shader source - const std::string sNormFS = - R"(#version 300 es - precision mediump float; - uniform mediump vec2 v; - layout(location = 0) out mediump vec4 fragColor; + constexpr char kSNormFS[] = R"(#version 300 es +precision mediump float; +uniform mediump vec2 v; +layout(location = 0) out mediump vec4 fragColor; - void main() - { - uint u = packSnorm2x16(v); - vec2 r = unpackSnorm2x16(u); - fragColor = vec4(r, 0.0, 1.0); - })"; +void main() +{ + uint u = packSnorm2x16(v); + vec2 r = unpackSnorm2x16(u); + fragColor = vec4(r, 0.0, 1.0); +})"; // Fragment Shader source - const std::string uNormFS = - R"(#version 300 es - precision mediump float; - uniform mediump vec2 v; - layout(location = 0) out mediump vec4 fragColor; + constexpr char kUNormFS[] = R"(#version 300 es +precision mediump float; +uniform mediump vec2 v; +layout(location = 0) out mediump vec4 fragColor; - void main() - { - uint u = packUnorm2x16(v); - vec2 r = unpackUnorm2x16(u); - fragColor = vec4(r, 0.0, 1.0); - })"; +void main() +{ + uint u = packUnorm2x16(v); + vec2 r = unpackUnorm2x16(u); + fragColor = vec4(r, 0.0, 1.0); +})"; // Fragment Shader source - const std::string halfFS = - R"(#version 300 es - precision mediump float; - uniform mediump vec2 v; - layout(location = 0) out mediump vec4 fragColor; + constexpr char kHalfFS[] = R"(#version 300 es +precision mediump float; +uniform mediump vec2 v; +layout(location = 0) out mediump vec4 fragColor; - void main() - { - uint u = packHalf2x16(v); - vec2 r = unpackHalf2x16(u); - fragColor = vec4(r, 0.0, 1.0); - })"; +void main() +{ + uint u = packHalf2x16(v); + vec2 r = unpackHalf2x16(u); + fragColor = vec4(r, 0.0, 1.0); +})"; - mSNormProgram = CompileProgram(essl3_shaders::vs::Simple(), sNormFS); - mUNormProgram = CompileProgram(essl3_shaders::vs::Simple(), uNormFS); - mHalfProgram = CompileProgram(essl3_shaders::vs::Simple(), halfFS); + mSNormProgram = CompileProgram(essl3_shaders::vs::Simple(), kSNormFS); + mUNormProgram = CompileProgram(essl3_shaders::vs::Simple(), kUNormFS); + mHalfProgram = CompileProgram(essl3_shaders::vs::Simple(), kHalfFS); if (mSNormProgram == 0 || mUNormProgram == 0 || mHalfProgram == 0) { FAIL() << "shader compilation failed."; diff --git a/src/tests/gl_tests/ParallelShaderCompileTest.cpp b/src/tests/gl_tests/ParallelShaderCompileTest.cpp index fd3277e17..1da63e446 100644 --- a/src/tests/gl_tests/ParallelShaderCompileTest.cpp +++ b/src/tests/gl_tests/ParallelShaderCompileTest.cpp @@ -54,8 +54,8 @@ class ParallelShaderCompileTest : public ANGLETest bool compile() { mVertexShader = - compileShader(GL_VERTEX_SHADER, insertRandomString(essl1_shaders::vs::Simple())); - mFragmentShader = compileShader(GL_FRAGMENT_SHADER, + CompileShader(GL_VERTEX_SHADER, insertRandomString(essl1_shaders::vs::Simple())); + mFragmentShader = CompileShader(GL_FRAGMENT_SHADER, insertRandomString(essl1_shaders::fs::UniformColor())); return (mVertexShader != 0 && mFragmentShader != 0); } @@ -123,7 +123,7 @@ class ParallelShaderCompileTest : public ANGLETest return ostream.str(); } - GLuint compileShader(GLenum type, const std::string &source) + GLuint CompileShader(GLenum type, const std::string &source) { GLuint shader = glCreateShader(type); diff --git a/src/tests/gl_tests/PathRenderingTest.cpp b/src/tests/gl_tests/PathRenderingTest.cpp index b76688eb1..8ece779e6 100644 --- a/src/tests/gl_tests/PathRenderingTest.cpp +++ b/src/tests/gl_tests/PathRenderingTest.cpp @@ -711,12 +711,12 @@ class CHROMIUMPathRenderingDrawTest : public ANGLETest glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glEnable(GL_STENCIL_TEST); - static const char *kVertexShaderSource = + constexpr char kVertexShaderSource[] = "void main() {\n" " gl_Position = vec4(1.0); \n" "}"; - static const char *kFragmentShaderSource = + constexpr char kFragmentShaderSource[] = "precision mediump float;\n" "uniform vec4 color;\n" "void main() {\n" @@ -1085,7 +1085,7 @@ class CHROMIUMPathRenderingWithTexturingTest : public ANGLETest // varying vec4 color; // // (? can be anything) - void compileProgram(const char *vertexShaderSource, const char *fragmentShaderSource) + void CompileProgram(const char *vertexShaderSource, const char *fragmentShaderSource) { glViewport(0, 0, kResolution, kResolution); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); @@ -1097,8 +1097,8 @@ class CHROMIUMPathRenderingWithTexturingTest : public ANGLETest ASSERT_GL_NO_ERROR(); - GLuint vShader = compileShader(GL_VERTEX_SHADER, vertexShaderSource); - GLuint fShader = compileShader(GL_FRAGMENT_SHADER, fragmentShaderSource); + GLuint vShader = CompileShader(GL_VERTEX_SHADER, vertexShaderSource); + GLuint fShader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSource); ASSERT_NE(0u, vShader); ASSERT_NE(0u, fShader); @@ -1266,7 +1266,7 @@ TEST_P(CHROMIUMPathRenderingWithTexturingTest, TestBindFragmentInputLocation) "}\n"; // clang-format on - compileProgram(kVertexShaderSource, kFragmentShaderSource); + CompileProgram(kVertexShaderSource, kFragmentShaderSource); enum kBindLocations { @@ -1337,7 +1337,7 @@ TEST_P(CHROMIUMPathRenderingWithTexturingTest, TestProgramPathFragmentInputGenCH "}\n"; // clang-format on - compileProgram(kVertexShaderSource, kFragmentShaderSource); + CompileProgram(kVertexShaderSource, kFragmentShaderSource); bindProgram(); ASSERT_TRUE(linkProgram() == true); @@ -1434,7 +1434,7 @@ TEST_P(CHROMIUMPathRenderingWithTexturingTest, TestProgramPathFragmentInputGenCH "}"; // clang-format on - compileProgram(kVertexShaderSource, kFragmentShaderSource); + CompileProgram(kVertexShaderSource, kFragmentShaderSource); bindProgram(); ASSERT_TRUE(linkProgram() == true); @@ -1564,7 +1564,7 @@ TEST_P(CHROMIUMPathRenderingWithTexturingTest, TestProgramPathFragmentInputGenAr {kMat4Location, "mat4_var", -1}, }; - compileProgram(kVertexShaderSource, kFragmentShaderSource); + CompileProgram(kVertexShaderSource, kFragmentShaderSource); for (size_t i = 0; i < ArraySize(variables); ++i) { @@ -1713,7 +1713,7 @@ TEST_P(CHROMIUMPathRenderingWithTexturingTest, TestConflictingBind) const GLint kColorALocation = 3; const GLint kColorBLocation = 4; - compileProgram(kVertexShaderSource, kFragmentShaderSource); + CompileProgram(kVertexShaderSource, kFragmentShaderSource); glBindFragmentInputLocationCHROMIUM(mProgram, kColorALocation, "colorA"); // Bind colorB to location a, causing conflicts. Linking should fail. @@ -1779,7 +1779,7 @@ TEST_P(CHROMIUMPathRenderingWithTexturingTest, BindFragmentInputArray) for (int pass = 0; pass < 2; ++pass) { - compileProgram(kVertexShaderSource, kFragmentShaderSource); + CompileProgram(kVertexShaderSource, kFragmentShaderSource); if (pass == 0) { glBindFragmentInputLocationCHROMIUM(mProgram, kUnusedLocation, "colorA[0]"); @@ -1876,7 +1876,7 @@ TEST_P(CHROMIUMPathRenderingWithTexturingTest, DISABLED_BindFragmentInputArrayNo const GLfloat kColor[] = {0.2f, 0.2f, 0.2f, 0.2f}; const GLfloat kFillCoords[6] = {59.0f, 50.0f, 50.0f, 28.0f, 66.0f, 63.0f}; - compileProgram(kVertexShaderSource, kFragmentShaderSource); + CompileProgram(kVertexShaderSource, kFragmentShaderSource); glBindFragmentInputLocationCHROMIUM(mProgram, kUnusedLocation, "colorA[0]"); glBindFragmentInputLocationCHROMIUM(mProgram, kColorA1Location, "colorA[1]"); @@ -1953,7 +1953,7 @@ TEST_P(CHROMIUMPathRenderingWithTexturingTest, UnusedFragmentInputUpdate) const GLint kNonexistingLocation = 5; const GLint kUnboundLocation = 6; - compileProgram(kVertexShaderString, kFragmentShaderString); + CompileProgram(kVertexShaderString, kFragmentShaderString); glBindFragmentInputLocationCHROMIUM(mProgram, kColorULocation, "u_colorU"); diff --git a/src/tests/gl_tests/PbufferTest.cpp b/src/tests/gl_tests/PbufferTest.cpp index d714494b2..48ccd6ef6 100644 --- a/src/tests/gl_tests/PbufferTest.cpp +++ b/src/tests/gl_tests/PbufferTest.cpp @@ -26,7 +26,7 @@ class PbufferTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vsSource = + constexpr char kVS[] = R"(precision highp float; attribute vec4 position; varying vec2 texcoord; @@ -38,7 +38,7 @@ class PbufferTest : public ANGLETest texcoord.y = 1.0 - texcoord.y; })"; - const std::string textureFSSource = + constexpr char kFS[] = R"(precision highp float; uniform sampler2D tex; varying vec2 texcoord; @@ -48,7 +48,7 @@ class PbufferTest : public ANGLETest gl_FragColor = texture2D(tex, texcoord); })"; - mTextureProgram = CompileProgram(vsSource, textureFSSource); + mTextureProgram = CompileProgram(kVS, kFS); if (mTextureProgram == 0) { FAIL() << "shader compilation failed."; diff --git a/src/tests/gl_tests/PointSpritesTest.cpp b/src/tests/gl_tests/PointSpritesTest.cpp index 7e48e5669..726d89ab4 100644 --- a/src/tests/gl_tests/PointSpritesTest.cpp +++ b/src/tests/gl_tests/PointSpritesTest.cpp @@ -178,14 +178,13 @@ TEST_P(PointSpritesTest, PointWithoutAttributesCompliance) GLfloat maxPointSize = pointSizeRange[1]; ANGLE_SKIP_TEST_IF(maxPointSize < kMinMaxPointSize); - const std::string vs = - R"(void main() - { - gl_PointSize = 2.0; - gl_Position = vec4(0.0, 0.0, 0.0, 1.0); - })"; + constexpr char kVS[] = R"(void main() +{ + gl_PointSize = 2.0; + gl_Position = vec4(0.0, 0.0, 0.0, 1.0); +})"; - ANGLE_GL_PROGRAM(program, vs, essl1_shaders::fs::Blue()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Blue()); ASSERT_GL_NO_ERROR(); glUseProgram(program); @@ -210,35 +209,33 @@ TEST_P(PointSpritesTest, PointCoordRegressionTest) GLfloat maxPointSize = pointSizeRange[1]; ANGLE_SKIP_TEST_IF(maxPointSize < kMinMaxPointSize); - const std::string fs = - R"(precision mediump float; - varying vec4 v_color; - void main() - { - // It seems as long as this mathematical expression references - // gl_PointCoord, the fragment's color is incorrect. - vec2 diff = gl_PointCoord - vec2(.5, .5); - if (length(diff) > 0.5) - discard; + constexpr char kFS[] = R"(precision mediump float; +varying vec4 v_color; +void main() +{ + // It seems as long as this mathematical expression references + // gl_PointCoord, the fragment's color is incorrect. + vec2 diff = gl_PointCoord - vec2(.5, .5); + if (length(diff) > 0.5) + discard; - // The point should be a solid color. - gl_FragColor = v_color; - })"; + // The point should be a solid color. + gl_FragColor = v_color; +})"; - const std::string vs = - R"(varying vec4 v_color; - // The X and Y coordinates of the center of the point. - attribute vec2 a_vertex; - uniform float u_pointSize; - void main() - { - gl_PointSize = u_pointSize; - gl_Position = vec4(a_vertex, 0.0, 1.0); - // The color of the point. - v_color = vec4(0.0, 1.0, 0.0, 1.0); - })"; + constexpr char kVS[] = R"(varying vec4 v_color; +// The X and Y coordinates of the center of the point. +attribute vec2 a_vertex; +uniform float u_pointSize; +void main() +{ + gl_PointSize = u_pointSize; + gl_Position = vec4(a_vertex, 0.0, 1.0); + // The color of the point. + v_color = vec4(0.0, 1.0, 0.0, 1.0); +})"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); ASSERT_GL_NO_ERROR(); glUseProgram(program); @@ -283,32 +280,30 @@ TEST_P(PointSpritesTest, PointSizeEnabledCompliance) // http://anglebug.com/1643 ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL() && IsWindows()); - const std::string fs = - R"(precision mediump float; - varying vec4 color; + constexpr char kFS[] = R"(precision mediump float; +varying vec4 color; - void main() - { - gl_FragColor = color; - })"; +void main() +{ + gl_FragColor = color; +})"; - const std::string vs = - R"(attribute vec3 pos; - attribute vec4 colorIn; - uniform float pointSize; - varying vec4 color; + constexpr char kVS[] = R"(attribute vec3 pos; +attribute vec4 colorIn; +uniform float pointSize; +varying vec4 color; - void main() - { - gl_PointSize = pointSize; - color = colorIn; - gl_Position = vec4(pos, 1.0); - })"; +void main() +{ + gl_PointSize = pointSize; + color = colorIn; + gl_Position = vec4(pos, 1.0); +})"; // The WebGL test is drawn on a 2x2 canvas. Emulate this by setting a 2x2 viewport. glViewport(0, 0, 2, 2); - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); ASSERT_GL_NO_ERROR(); glUseProgram(program); @@ -401,16 +396,14 @@ TEST_P(PointSpritesTest, PointSizeEnabledCompliance) // Verify that rendering works correctly when gl_PointSize is declared in a shader but isn't used TEST_P(PointSpritesTest, PointSizeDeclaredButUnused) { - const std::string vs = - R"(attribute highp vec4 position; + constexpr char kVS[] = R"(attribute highp vec4 position; +void main(void) +{ + gl_PointSize = 1.0; + gl_Position = position; +})"; - void main(void) - { - gl_PointSize = 1.0; - gl_Position = position; - })"; - - ANGLE_GL_PROGRAM(program, vs, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); ASSERT_GL_NO_ERROR(); glUseProgram(program); @@ -431,16 +424,14 @@ TEST_P(PointSpritesTest, PointSpriteAlternatingDrawTypes) GLfloat maxPointSize = pointSizeRange[1]; ANGLE_SKIP_TEST_IF(maxPointSize < kMinMaxPointSize); - const std::string pointVS = - R"(uniform float u_pointSize; + constexpr char kVS[] = R"(uniform float u_pointSize; +void main() +{ + gl_PointSize = u_pointSize; + gl_Position = vec4(0.0, 0.0, 0.0, 1.0); +})"; - void main() - { - gl_PointSize = u_pointSize; - gl_Position = vec4(0.0, 0.0, 0.0, 1.0); - })"; - - ANGLE_GL_PROGRAM(pointProgram, pointVS, essl1_shaders::fs::Blue()); + ANGLE_GL_PROGRAM(pointProgram, kVS, essl1_shaders::fs::Blue()); ANGLE_GL_PROGRAM(quadProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red()); ASSERT_GL_NO_ERROR(); @@ -501,7 +492,7 @@ TEST_P(PointSpritesTest, PointSizeAboveMaxIsClamped) return; } - const std::string &vs = + constexpr char kVS[] = "attribute vec4 vPosition;\n" "uniform float uPointSize;\n" "void main()\n" @@ -509,7 +500,7 @@ TEST_P(PointSpritesTest, PointSizeAboveMaxIsClamped) " gl_PointSize = uPointSize;\n" " gl_Position = vPosition;\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); glUseProgram(program); ASSERT_GL_NO_ERROR(); diff --git a/src/tests/gl_tests/ProgramBinaryTest.cpp b/src/tests/gl_tests/ProgramBinaryTest.cpp index 51fcc56e2..7bdfc8c8d 100644 --- a/src/tests/gl_tests/ProgramBinaryTest.cpp +++ b/src/tests/gl_tests/ProgramBinaryTest.cpp @@ -269,7 +269,7 @@ void ProgramBinaryES3Test::testBinaryAndUBOBlockIndexes(bool drawWithProgramFirs glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &binaryFormatCount); ANGLE_SKIP_TEST_IF(!binaryFormatCount); - const std::string &vertexShader = + constexpr char kVS[] = "#version 300 es\n" "uniform block {\n" " float f;\n" @@ -280,7 +280,8 @@ void ProgramBinaryES3Test::testBinaryAndUBOBlockIndexes(bool drawWithProgramFirs " gl_Position = position;\n" " color = vec4(f, f, f, 1);\n" "}"; - const std::string &fragmentShader = + + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "in vec4 color;\n" @@ -290,7 +291,7 @@ void ProgramBinaryES3Test::testBinaryAndUBOBlockIndexes(bool drawWithProgramFirs "}"; // Init and draw with the program. - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); float fData[4] = {1.0f, 1.0f, 1.0f, 1.0f}; GLuint bindIndex = 2; @@ -378,7 +379,7 @@ TEST_P(ProgramBinaryES31Test, ProgramBinaryWithComputeShader) glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &binaryFormatCount); ANGLE_SKIP_TEST_IF(!binaryFormatCount); - const std::string &computeShader = + constexpr char kCS[] = "#version 310 es\n" "layout(local_size_x=4, local_size_y=3, local_size_z=1) in;\n" "uniform block {\n" @@ -390,7 +391,7 @@ TEST_P(ProgramBinaryES31Test, ProgramBinaryWithComputeShader) " vec4 color = texture(tex, f + g);\n" "}"; - ANGLE_GL_COMPUTE_PROGRAM(program, computeShader); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); // Read back the binary. GLint programLength = 0; @@ -494,30 +495,27 @@ class ProgramBinaryTransformFeedbackTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vertexShaderSource = - R"(#version 300 es - in vec4 inputAttribute; - out vec4 outputVarying; - void main() - { - outputVarying = inputAttribute; - })"; + constexpr char kVS[] = R"(#version 300 es +in vec4 inputAttribute; +out vec4 outputVarying; +void main() +{ + outputVarying = inputAttribute; +})"; - const std::string fragmentShaderSource = - R"(#version 300 es - precision highp float; - out vec4 outputColor; - void main() - { - outputColor = vec4(1,0,0,1); - })"; + constexpr char kFS[] = R"(#version 300 es +precision highp float; +out vec4 outputColor; +void main() +{ + outputColor = vec4(1,0,0,1); +})"; std::vector transformFeedbackVaryings; transformFeedbackVaryings.push_back("outputVarying"); - mProgram = - CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - transformFeedbackVaryings, GL_SEPARATE_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, transformFeedbackVaryings, + GL_SEPARATE_ATTRIBS); if (mProgram == 0) { FAIL() << "shader compilation failed."; @@ -707,7 +705,7 @@ class ProgramBinariesAcrossPlatforms : public testing::TestWithParam tfVaryings; tfVaryings.push_back("outArrayElements[7]"); @@ -845,8 +841,8 @@ TEST_P(ProgramInterfaceTestES31, QueryTransformFeedbackVarying) tfVaryings.push_back("outSingleType"); tfVaryings.push_back("outWholeArray"); - GLuint program = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + GLuint program = + CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, program); GLint num; diff --git a/src/tests/gl_tests/ProvokingVertexTest.cpp b/src/tests/gl_tests/ProvokingVertexTest.cpp index 2f770930e..aae336f92 100644 --- a/src/tests/gl_tests/ProvokingVertexTest.cpp +++ b/src/tests/gl_tests/ProvokingVertexTest.cpp @@ -40,7 +40,7 @@ class ProvokingVertexTest : public ANGLETest { ANGLETest::SetUp(); - const std::string &vertexShader = + constexpr char kVS[] = "#version 300 es\n" "in int intAttrib;\n" "in vec2 position;\n" @@ -50,7 +50,7 @@ class ProvokingVertexTest : public ANGLETest " attrib = intAttrib;\n" "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "flat in int attrib;\n" "out int fragColor;\n" @@ -60,8 +60,7 @@ class ProvokingVertexTest : public ANGLETest std::vector tfVaryings; tfVaryings.push_back("attrib"); - mProgram = CompileProgramWithTransformFeedback(vertexShader, fragmentShader, tfVaryings, - GL_SEPARATE_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_SEPARATE_ATTRIBS); ASSERT_NE(0u, mProgram); glGenTextures(1, &mTexture); diff --git a/src/tests/gl_tests/ReadPixelsTest.cpp b/src/tests/gl_tests/ReadPixelsTest.cpp index bf2258e6d..da93ccc76 100644 --- a/src/tests/gl_tests/ReadPixelsTest.cpp +++ b/src/tests/gl_tests/ReadPixelsTest.cpp @@ -286,7 +286,7 @@ class ReadPixelsPBODrawTest : public ReadPixelsPBOTest { ReadPixelsPBOTest::SetUp(); - const char *vertexShaderSrc = + constexpr char kVS[] = "attribute vec4 aTest; attribute vec2 aPosition; varying vec4 vTest;\n" "void main()\n" "{\n" @@ -295,14 +295,14 @@ class ReadPixelsPBODrawTest : public ReadPixelsPBOTest " gl_PointSize = 1.0;\n" "}"; - const char *fragmentShaderSrc = + constexpr char kFS[] = "precision mediump float; varying vec4 vTest;\n" "void main()\n" "{\n" " gl_FragColor = vTest;\n" "}"; - mProgram = CompileProgram(vertexShaderSrc, fragmentShaderSrc); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); glGenBuffers(1, &mPositionVBO); diff --git a/src/tests/gl_tests/RobustBufferAccessBehaviorTest.cpp b/src/tests/gl_tests/RobustBufferAccessBehaviorTest.cpp index e823dd872..238ba3f8f 100644 --- a/src/tests/gl_tests/RobustBufferAccessBehaviorTest.cpp +++ b/src/tests/gl_tests/RobustBufferAccessBehaviorTest.cpp @@ -57,7 +57,7 @@ class RobustBufferAccessBehaviorTest : public ANGLETest void initBasicProgram() { - const std::string &vsCheckOutOfBounds = + constexpr char kVS[] = "precision mediump float;\n" "attribute vec4 position;\n" "attribute vec4 vecRandom;\n" @@ -80,14 +80,14 @@ class RobustBufferAccessBehaviorTest : public ANGLETest " gl_Position = position;\n" "}\n"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "precision mediump float;\n" "varying vec4 v_color;\n" "void main() {\n" " gl_FragColor = v_color;\n" "}\n"; - mProgram = CompileProgram(vsCheckOutOfBounds, fragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); mTestAttrib = glGetAttribLocation(mProgram, "vecRandom"); diff --git a/src/tests/gl_tests/RobustResourceInitTest.cpp b/src/tests/gl_tests/RobustResourceInitTest.cpp index 2e7e8edb0..31ec69626 100644 --- a/src/tests/gl_tests/RobustResourceInitTest.cpp +++ b/src/tests/gl_tests/RobustResourceInitTest.cpp @@ -11,6 +11,15 @@ namespace angle { +constexpr char kSimpleTextureVertexShader[] = + "#version 300 es\n" + "in vec4 position;\n" + "out vec2 texcoord;\n" + "void main()\n" + "{\n" + " gl_Position = position;\n" + " texcoord = vec2(position.xy * 0.5 - 0.5);\n" + "}"; // TODO(jmadill): Would be useful in a shared place in a utils folder. void UncompressDXTBlock(int destX, @@ -248,16 +257,6 @@ class RobustResourceInitTest : public ANGLETest int skipHeight, const GLColor &skip); - const std::string kSimpleTextureVertexShader = - "#version 300 es\n" - "in vec4 position;\n" - "out vec2 texcoord;\n" - "void main()\n" - "{\n" - " gl_Position = position;\n" - " texcoord = vec2(position.xy * 0.5 - 0.5);\n" - "}"; - static std::string GetSimpleTextureFragmentShader(const char *samplerType) { std::stringstream fragmentStream; @@ -342,7 +341,7 @@ TEST_P(RobustResourceInitTest, BufferData) glBufferData(GL_ARRAY_BUFFER, getWindowWidth() * getWindowHeight() * sizeof(GLfloat), nullptr, GL_STATIC_DRAW); - const std::string &vertexShader = + constexpr char kVS[] = "attribute vec2 position;\n" "attribute float testValue;\n" "varying vec4 colorOut;\n" @@ -350,13 +349,13 @@ TEST_P(RobustResourceInitTest, BufferData) " gl_Position = vec4(position, 0, 1);\n" " colorOut = testValue == 0.0 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "varying mediump vec4 colorOut;\n" "void main() {\n" " gl_FragColor = colorOut;\n" "}"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); GLint testValueLoc = glGetAttribLocation(program.get(), "testValue"); ASSERT_NE(-1, testValueLoc); @@ -704,14 +703,14 @@ TEST_P(RobustResourceInitTest, DrawWithTexture) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - const std::string &vertexShader = + constexpr char kVS[] = "attribute vec2 position;\n" "varying vec2 texCoord;\n" "void main() {\n" " gl_Position = vec4(position, 0, 1);\n" " texCoord = (position * 0.5) + 0.5;\n" "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "varying vec2 texCoord;\n" "uniform sampler2D tex;\n" @@ -719,7 +718,7 @@ TEST_P(RobustResourceInitTest, DrawWithTexture) " gl_FragColor = texture2D(tex, texCoord);\n" "}"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program, "position", 0.5f); checkFramebufferNonZeroPixels(0, 0, 0, 0, GLColor::black); @@ -935,8 +934,9 @@ void RobustResourceInitTestES3::testIntegerTextureInit(const char *samplerType, { ANGLE_SKIP_TEST_IF(!hasGLExtension()); - ANGLE_GL_PROGRAM(program, kSimpleTextureVertexShader, - GetSimpleTextureFragmentShader(samplerType)); + std::string fs = GetSimpleTextureFragmentShader(samplerType); + + ANGLE_GL_PROGRAM(program, kSimpleTextureVertexShader, fs.c_str()); // Make an RGBA framebuffer. GLTexture framebufferTexture; @@ -1011,7 +1011,7 @@ TEST_P(RobustResourceInitTestES3, TextureInit_IntRGB32) TEST_P(RobustResourceInitTestES31, ImageTextureInit_R32UI) { ANGLE_SKIP_TEST_IF(!hasGLExtension()); - const std::string csSource = + constexpr char kCS[] = R"(#version 310 es layout(local_size_x=1, local_size_y=1, local_size_z=1) in; layout(r32ui, binding = 1) writeonly uniform highp uimage2D writeImage; @@ -1026,7 +1026,7 @@ TEST_P(RobustResourceInitTestES31, ImageTextureInit_R32UI) glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, 1, 1); EXPECT_GL_NO_ERROR(); - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); glBindImageTexture(1, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32UI); @@ -1076,7 +1076,8 @@ TEST_P(RobustResourceInitTestES3, GenerateMipmap) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - ANGLE_GL_PROGRAM(program, kSimpleTextureVertexShader, GetSimpleTextureFragmentShader("")); + std::string shader = GetSimpleTextureFragmentShader(""); + ANGLE_GL_PROGRAM(program, kSimpleTextureVertexShader, shader.c_str()); // Generate mipmaps and verify all the mips. glGenerateMipmap(GL_TEXTURE_2D); diff --git a/src/tests/gl_tests/SRGBTextureTest.cpp b/src/tests/gl_tests/SRGBTextureTest.cpp index eb899b0ee..cfd456680 100644 --- a/src/tests/gl_tests/SRGBTextureTest.cpp +++ b/src/tests/gl_tests/SRGBTextureTest.cpp @@ -27,7 +27,7 @@ class SRGBTextureTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vs = + constexpr char kVS[] = "precision highp float;\n" "attribute vec4 position;\n" "varying vec2 texcoord;\n" @@ -38,7 +38,7 @@ class SRGBTextureTest : public ANGLETest " texcoord = (position.xy * 0.5) + 0.5;\n" "}\n"; - const std::string fs = + constexpr char kFS[] = "precision highp float;\n" "uniform sampler2D tex;\n" "varying vec2 texcoord;\n" @@ -48,7 +48,7 @@ class SRGBTextureTest : public ANGLETest " gl_FragColor = texture2D(tex, texcoord);\n" "}\n"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); mTextureLocation = glGetUniformLocation(mProgram, "tex"); diff --git a/src/tests/gl_tests/ShaderStorageBufferTest.cpp b/src/tests/gl_tests/ShaderStorageBufferTest.cpp index b06fdd647..034c7e635 100644 --- a/src/tests/gl_tests/ShaderStorageBufferTest.cpp +++ b/src/tests/gl_tests/ShaderStorageBufferTest.cpp @@ -149,7 +149,7 @@ class ShaderStorageBufferTest31 : public ANGLETest // declarations with the same sequence of types. TEST_P(ShaderStorageBufferTest31, MatchedBlockNameWithDifferentMemberType) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "buffer blockName {\n" " float data;\n" @@ -157,7 +157,7 @@ TEST_P(ShaderStorageBufferTest31, MatchedBlockNameWithDifferentMemberType) "void main()\n" "{\n" "}\n"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "buffer blockName {\n" " uint data;\n" @@ -166,7 +166,7 @@ TEST_P(ShaderStorageBufferTest31, MatchedBlockNameWithDifferentMemberType) "{\n" "}\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } @@ -189,13 +189,13 @@ TEST_P(ShaderStorageBufferTest31, ExceedMaxVertexShaderStorageBlocks) "void main()\n" "{\n" "}\n"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "void main()\n" "{\n" "}\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(vertexShaderSource.c_str(), kFS); EXPECT_EQ(0u, program); } @@ -250,14 +250,14 @@ TEST_P(ShaderStorageBufferTest31, ExceedMaxCombinedShaderStorageBlocks) "{\n" "}\n"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str()); EXPECT_EQ(0u, program); } // Test shader storage buffer read write. TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferReadWrite) { - const std::string &csSource = + constexpr char kCS[] = "#version 310 es\n" "layout(local_size_x=1, local_size_y=1, local_size_z=1) in;\n" "layout(std140, binding = 1) buffer blockName {\n" @@ -269,7 +269,7 @@ TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferReadWrite) " instanceName.data[1] = 4u;\n" "}\n"; - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); @@ -797,8 +797,7 @@ void main() // Test that access/write to array of array structure data in shader storage buffer. TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferStructureArrayOfArray) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout(local_size_x=1, local_size_y=1, local_size_z=1) in; struct S { @@ -914,8 +913,7 @@ void main() // Test that access/write to vector data in std430 shader storage block. TEST_P(ShaderStorageBufferTest31, VectorArrayInSSBOWithStd430Qualifier) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout(local_size_x=1, local_size_y=1, local_size_z=1) in; layout(std430, binding = 0) buffer blockIn { uvec2 data[2]; @@ -973,8 +971,7 @@ void main() // Test that access/write to matrix data in std430 shader storage block. TEST_P(ShaderStorageBufferTest31, MatrixInSSBOWithStd430Qualifier) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout(local_size_x=1, local_size_y=1, local_size_z=1) in; layout(std430, binding = 0) buffer blockIn { mat2 data; @@ -1004,8 +1001,7 @@ void main() // Test that access/write to structure data in std430 shader storage block. TEST_P(ShaderStorageBufferTest31, StructureInSSBOWithStd430Qualifier) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout(local_size_x=1, local_size_y=1, local_size_z=1) in; struct S { @@ -1084,8 +1080,7 @@ void main() // Test that access/write to structure of structure data in std430 shader storage block. TEST_P(ShaderStorageBufferTest31, StructureOfStructureInSSBOWithStd430Qualifier) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout(local_size_x=1, local_size_y=1, local_size_z=1) in; struct S2 { @@ -1182,24 +1177,21 @@ TEST_P(ShaderStorageBufferTest31, AtomicMemoryFunctions) // supported on d3d backend. http://anglebug.com/1951 ANGLE_SKIP_TEST_IF(IsD3D11()); - const std::string &csSource = - R"(#version 310 es + constexpr char kCS[] = R"(#version 310 es +layout(local_size_x=1, local_size_y=1, local_size_z=1) in; +layout(std140, binding = 1) buffer blockName { + uint data[2]; +} instanceName; - layout(local_size_x=1, local_size_y=1, local_size_z=1) in; - layout(std140, binding = 1) buffer blockName { - uint data[2]; - } instanceName; +void main() +{ + instanceName.data[0] = 0u; + instanceName.data[1] = 0u; + atomicAdd(instanceName.data[0], 5u); + atomicMax(instanceName.data[1], 7u); +})"; - void main() - { - instanceName.data[0] = 0u; - instanceName.data[1] = 0u; - atomicAdd(instanceName.data[0], 5u); - atomicMax(instanceName.data[1], 7u); - - })"; - - ANGLE_GL_COMPUTE_PROGRAM(program, csSource); + ANGLE_GL_COMPUTE_PROGRAM(program, kCS); glUseProgram(program.get()); @@ -1241,37 +1233,35 @@ TEST_P(ShaderStorageBufferTest31, AtomicMemoryFunctions) // bindings again. TEST_P(ShaderStorageBufferTest31, MultiStorageBuffersForMultiPrograms) { - const std::string &csSource1 = - R"(#version 310 es - layout(local_size_x=3, local_size_y=1, local_size_z=1) in; - layout(binding = 1) buffer Output { - uint result1[]; - } sb_out1; - void main() - { - highp uint offset = gl_LocalInvocationID.x; - sb_out1.result1[gl_LocalInvocationIndex] = gl_LocalInvocationIndex + 1u; - })"; + constexpr char kCS1[] = R"(#version 310 es +layout(local_size_x=3, local_size_y=1, local_size_z=1) in; +layout(binding = 1) buffer Output { + uint result1[]; +} sb_out1; +void main() +{ + highp uint offset = gl_LocalInvocationID.x; + sb_out1.result1[gl_LocalInvocationIndex] = gl_LocalInvocationIndex + 1u; +})"; - const std::string &csSource2 = - R"(#version 310 es - layout(local_size_x=3, local_size_y=1, local_size_z=1) in; - layout(binding = 2) buffer Output { - uint result2[]; - } sb_out2; - void main() - { - highp uint offset = gl_LocalInvocationID.x; - sb_out2.result2[gl_LocalInvocationIndex] = gl_LocalInvocationIndex + 2u; - })"; + constexpr char kCS2[] = R"(#version 310 es +layout(local_size_x=3, local_size_y=1, local_size_z=1) in; +layout(binding = 2) buffer Output { + uint result2[]; +} sb_out2; +void main() +{ + highp uint offset = gl_LocalInvocationID.x; + sb_out2.result2[gl_LocalInvocationIndex] = gl_LocalInvocationIndex + 2u; +})"; constexpr unsigned int numInvocations = 3; int arrayStride1 = 0, arrayStride2 = 0; GLenum props[] = {GL_ARRAY_STRIDE}; GLBuffer shaderStorageBuffer1, shaderStorageBuffer2; - ANGLE_GL_COMPUTE_PROGRAM(program1, csSource1); - ANGLE_GL_COMPUTE_PROGRAM(program2, csSource2); + ANGLE_GL_COMPUTE_PROGRAM(program1, kCS1); + ANGLE_GL_COMPUTE_PROGRAM(program2, kCS2); EXPECT_GL_NO_ERROR(); unsigned int outVarIndex1 = @@ -1327,8 +1317,7 @@ TEST_P(ShaderStorageBufferTest31, MultiStorageBuffersForMultiPrograms) // Test that function calling is supported in SSBO access chain. TEST_P(ShaderStorageBufferTest31, FunctionCallInSSBOAccessChain) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout (local_size_x=4) in; highp uint getIndex (in highp uvec2 localID, uint element) { @@ -1352,8 +1341,7 @@ void main() // Test that unary operator is supported in SSBO access chain. TEST_P(ShaderStorageBufferTest31, UnaryOperatorInSSBOAccessChain) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout (local_size_x=4) in; layout(binding=0, std430) buffer Storage { @@ -1374,8 +1362,7 @@ void main() // Test that ternary operator is supported in SSBO access chain. TEST_P(ShaderStorageBufferTest31, TernaryOperatorInSSBOAccessChain) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout (local_size_x=4) in; layout(binding=0, std430) buffer Storage { @@ -1399,8 +1386,7 @@ TEST_P(ShaderStorageBufferTest31, LoadAndStoreBooleanValue) // http://anglebug.com/1951 ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux()); - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout (local_size_x=1) in; layout(binding=0, std140) buffer Storage0 { @@ -1464,8 +1450,7 @@ void main() // Test that non-structure array of arrays is supported in SSBO. TEST_P(ShaderStorageBufferTest31, SimpleArrayOfArrays) { - constexpr char kComputeShaderSource[] = - R"(#version 310 es + constexpr char kComputeShaderSource[] = R"(#version 310 es layout (local_size_x=1) in; layout(binding=0, std140) buffer Storage0 { diff --git a/src/tests/gl_tests/SimpleOperationTest.cpp b/src/tests/gl_tests/SimpleOperationTest.cpp index acd3f26e4..09ccb1e77 100644 --- a/src/tests/gl_tests/SimpleOperationTest.cpp +++ b/src/tests/gl_tests/SimpleOperationTest.cpp @@ -49,6 +49,11 @@ class SimpleOperationTest : public ANGLETest } void verifyBuffer(const std::vector &data, GLenum binding); + + template + void testDrawElementsLineLoopUsingClientSideMemory(GLenum indexType, + int windowWidth, + int windowHeight); }; void SimpleOperationTest::verifyBuffer(const std::vector &data, GLenum binding) @@ -161,15 +166,14 @@ TEST_P(SimpleOperationTest, CompileVertexShader) TEST_P(SimpleOperationTest, CompileFragmentShaderSingleVaryingInput) { - const std::string source = - R"(precision mediump float; - varying vec4 v_input; - void main() - { - gl_FragColor = v_input; - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec4 v_input; +void main() +{ + gl_FragColor = v_input; +})"; - GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); + GLuint shader = CompileShader(GL_FRAGMENT_SHADER, kFS); EXPECT_NE(shader, 0u); glDeleteShader(shader); @@ -214,68 +218,47 @@ TEST_P(SimpleOperationTest, ScissorTest) TEST_P(SimpleOperationTest, LinkProgramShadersNoInputs) { - const std::string vsSource = - R"(void main() - { - gl_Position = vec4(1.0, 1.0, 1.0, 1.0); - })"; - - const std::string fsSource = - R"(void main() - { - gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); - })"; - - const GLuint program = CompileProgram(vsSource, fsSource); - EXPECT_NE(program, 0u); - glDeleteProgram(program); + constexpr char kVS[] = "void main() { gl_Position = vec4(1.0, 1.0, 1.0, 1.0); }"; + constexpr char kFS[] = "void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }"; + ANGLE_GL_PROGRAM(program, kVS, kFS); ASSERT_GL_NO_ERROR(); } TEST_P(SimpleOperationTest, LinkProgramWithUniforms) { - const std::string vsSource = - R"(void main() - { - gl_Position = vec4(1.0, 1.0, 1.0, 1.0); - })"; - const std::string fsSource = - R"(precision mediump float; - uniform vec4 u_input; - void main() - { - gl_FragColor = u_input; - })"; + constexpr char kVS[] = R"(void main() +{ + gl_Position = vec4(1.0, 1.0, 1.0, 1.0); +})"; + constexpr char kFS[] = R"(precision mediump float; +uniform vec4 u_input; +void main() +{ + gl_FragColor = u_input; +})"; - const GLuint program = CompileProgram(vsSource, fsSource); - EXPECT_NE(program, 0u); + ANGLE_GL_PROGRAM(program, kVS, kFS); const GLint uniformLoc = glGetUniformLocation(program, "u_input"); EXPECT_NE(-1, uniformLoc); - glDeleteProgram(program); - ASSERT_GL_NO_ERROR(); } TEST_P(SimpleOperationTest, LinkProgramWithAttributes) { - const std::string vsSource = - R"(attribute vec4 a_input; - void main() - { - gl_Position = a_input; - })"; + constexpr char kVS[] = R"(attribute vec4 a_input; +void main() +{ + gl_Position = a_input; +})"; - const GLuint program = CompileProgram(vsSource, kGreenFragmentShader); - EXPECT_NE(program, 0u); + ANGLE_GL_PROGRAM(program, kVS, kGreenFragmentShader); const GLint attribLoc = glGetAttribLocation(program, "a_input"); EXPECT_NE(-1, attribLoc); - glDeleteProgram(program); - ASSERT_GL_NO_ERROR(); } @@ -586,13 +569,13 @@ TEST_P(SimpleOperationTest, DrawIndexedQuadAndSwap) // Draw with a fragment uniform. TEST_P(SimpleOperationTest, DrawQuadWithFragmentUniform) { - const std::string &fragmentShader = + constexpr char kFS[] = "uniform mediump vec4 color;\n" "void main()\n" "{\n" " gl_FragColor = color;\n" "}"; - ANGLE_GL_PROGRAM(program, kBasicVertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kBasicVertexShader, kFS); GLint location = glGetUniformLocation(program, "color"); ASSERT_NE(-1, location); @@ -609,7 +592,7 @@ TEST_P(SimpleOperationTest, DrawQuadWithFragmentUniform) // Draw with a vertex uniform. TEST_P(SimpleOperationTest, DrawQuadWithVertexUniform) { - const std::string &vertexShader = + constexpr char kVS[] = "attribute vec3 position;\n" "uniform vec4 color;\n" "varying vec4 vcolor;\n" @@ -618,13 +601,13 @@ TEST_P(SimpleOperationTest, DrawQuadWithVertexUniform) " gl_Position = vec4(position, 1);\n" " vcolor = color;\n" "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "varying mediump vec4 vcolor;\n" "void main()\n" "{\n" " gl_FragColor = vcolor;\n" "}"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); const GLint location = glGetUniformLocation(program, "color"); ASSERT_NE(-1, location); @@ -641,7 +624,7 @@ TEST_P(SimpleOperationTest, DrawQuadWithVertexUniform) // Draw with two uniforms. TEST_P(SimpleOperationTest, DrawQuadWithTwoUniforms) { - const std::string &vertexShader = + constexpr char kVS[] = "attribute vec3 position;\n" "uniform vec4 color1;\n" "varying vec4 vcolor1;\n" @@ -650,14 +633,14 @@ TEST_P(SimpleOperationTest, DrawQuadWithTwoUniforms) " gl_Position = vec4(position, 1);\n" " vcolor1 = color1;\n" "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "uniform mediump vec4 color2;\n" "varying mediump vec4 vcolor1;\n" "void main()\n" "{\n" " gl_FragColor = vcolor1 + color2;\n" "}"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); const GLint location1 = glGetUniformLocation(program, "color1"); ASSERT_NE(-1, location1); @@ -678,8 +661,7 @@ TEST_P(SimpleOperationTest, DrawQuadWithTwoUniforms) // Tests a shader program with more than one vertex attribute, with vertex buffers. TEST_P(SimpleOperationTest, ThreeVertexAttributes) { - const std::string vertexShader = - R"(attribute vec2 position; + constexpr char kVS[] = R"(attribute vec2 position; attribute vec4 color1; attribute vec4 color2; varying vec4 color; @@ -689,8 +671,7 @@ void main() color = color1 + color2; })"; - const std::string fragmentShader = - R"(precision mediump float; + constexpr char kFS[] = R"(precision mediump float; varying vec4 color; void main() { @@ -698,7 +679,7 @@ void main() } )"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); @@ -821,9 +802,9 @@ TEST_P(SimpleOperationTest, DrawWith2DTexture) } template -void TestDrawElementsLineLoopUsingClientSideMemory(GLenum indexType, - int windowWidth, - int windowHeight) +void SimpleOperationTest::testDrawElementsLineLoopUsingClientSideMemory(GLenum indexType, + int windowWidth, + int windowHeight) { ANGLE_GL_PROGRAM(program, kBasicVertexShader, kGreenFragmentShader); glUseProgram(program); @@ -871,14 +852,14 @@ void TestDrawElementsLineLoopUsingClientSideMemory(GLenum indexType, // Draw a line loop using a drawElement call and client side memory. TEST_P(SimpleOperationTest, DrawElementsLineLoopUsingUShortClientSideMemory) { - TestDrawElementsLineLoopUsingClientSideMemory(GL_UNSIGNED_SHORT, getWindowWidth(), + testDrawElementsLineLoopUsingClientSideMemory(GL_UNSIGNED_SHORT, getWindowWidth(), getWindowHeight()); } // Draw a line loop using a drawElement call and client side memory. TEST_P(SimpleOperationTest, DrawElementsLineLoopUsingUByteClientSideMemory) { - TestDrawElementsLineLoopUsingClientSideMemory(GL_UNSIGNED_BYTE, getWindowWidth(), + testDrawElementsLineLoopUsingClientSideMemory(GL_UNSIGNED_BYTE, getWindowWidth(), getWindowHeight()); } diff --git a/src/tests/gl_tests/SixteenBppTextureTest.cpp b/src/tests/gl_tests/SixteenBppTextureTest.cpp index 8909c06f5..95346c3dd 100644 --- a/src/tests/gl_tests/SixteenBppTextureTest.cpp +++ b/src/tests/gl_tests/SixteenBppTextureTest.cpp @@ -50,28 +50,26 @@ class SixteenBppTextureTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vertexShaderSource = - R"(precision highp float; - attribute vec4 position; - varying vec2 texcoord; + constexpr char kVS[] = R"(precision highp float; +attribute vec4 position; +varying vec2 texcoord; - void main() - { - gl_Position = vec4(position.xy, 0.0, 1.0); - texcoord = (position.xy * 0.5) + 0.5; - })"; +void main() +{ + gl_Position = vec4(position.xy, 0.0, 1.0); + texcoord = (position.xy * 0.5) + 0.5; +})"; - const std::string fragmentShaderSource2D = - R"(precision highp float; - uniform sampler2D tex; - varying vec2 texcoord; + constexpr char kFS[] = R"(precision highp float; +uniform sampler2D tex; +varying vec2 texcoord; - void main() - { - gl_FragColor = texture2D(tex, texcoord); - })"; +void main() +{ + gl_FragColor = texture2D(tex, texcoord); +})"; - m2DProgram = CompileProgram(vertexShaderSource, fragmentShaderSource2D); + m2DProgram = CompileProgram(kVS, kFS); mTexture2DUniformLocation = glGetUniformLocation(m2DProgram, "tex"); } @@ -420,7 +418,7 @@ TEST_P(SixteenBppTextureTestES3, RGB565FramebufferReadback) fourColors.push_back(GLColor::blue); fourColors.push_back(GLColor::white); - const std::string &vertexShader = + constexpr char kVS[] = "#version 300 es\n" "in vec4 color;\n" "in vec2 position;\n" @@ -429,7 +427,7 @@ TEST_P(SixteenBppTextureTestES3, RGB565FramebufferReadback) " fcolor = color;\n" " gl_Position = vec4(position, 0.5, 1.0);\n" "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "in mediump vec4 fcolor;\n" "out mediump vec4 color;\n" @@ -437,7 +435,7 @@ TEST_P(SixteenBppTextureTestES3, RGB565FramebufferReadback) " color = fcolor;\n" "}"; - GLuint program = CompileProgram(vertexShader, fragmentShader); + GLuint program = CompileProgram(kVS, kFS); glUseProgram(program); GLint colorLocation = glGetAttribLocation(program, "color"); diff --git a/src/tests/gl_tests/StateChangeTest.cpp b/src/tests/gl_tests/StateChangeTest.cpp index 1142c461e..7b4fe4084 100644 --- a/src/tests/gl_tests/StateChangeTest.cpp +++ b/src/tests/gl_tests/StateChangeTest.cpp @@ -486,18 +486,18 @@ class StateChangeRenderTest : public StateChangeTest { StateChangeTest::SetUp(); - const std::string vertexShaderSource = + constexpr char kVS[] = "attribute vec2 position;\n" "void main() {\n" " gl_Position = vec4(position, 0, 1);\n" "}"; - const std::string fragmentShaderSource = + constexpr char kFS[] = "uniform highp vec4 uniformColor;\n" "void main() {\n" " gl_FragColor = uniformColor;\n" "}"; - mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); glGenRenderbuffers(1, &mRenderbuffer); @@ -699,7 +699,7 @@ TEST_P(StateChangeTest, VertexBufferUpdatedAfterDraw) // http://anglebug.com/2664. ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel()); - const std::string vs = + constexpr char kVS[] = "attribute vec2 position;\n" "attribute vec4 color;\n" "varying vec4 outcolor;\n" @@ -708,14 +708,14 @@ TEST_P(StateChangeTest, VertexBufferUpdatedAfterDraw) " gl_Position = vec4(position, 0, 1);\n" " outcolor = color;\n" "}"; - const std::string fs = + constexpr char kFS[] = "varying mediump vec4 outcolor;\n" "void main()\n" "{\n" " gl_FragColor = outcolor;\n" "}"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); GLint colorLoc = glGetAttribLocation(program, "color"); @@ -755,12 +755,11 @@ TEST_P(StateChangeTest, VertexBufferUpdatedAfterDraw) // Test that switching VAOs keeps the disabled "current value" attributes up-to-date. TEST_P(StateChangeTestES3, VertexArrayObjectAndDisabledAttributes) { - const std::string singleVertexShader = - "attribute vec4 position; void main() { gl_Position = position; }"; - const std::string singleFragmentShader = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }"; - ANGLE_GL_PROGRAM(singleProgram, singleVertexShader, singleFragmentShader); + constexpr char kSingleVS[] = "attribute vec4 position; void main() { gl_Position = position; }"; + constexpr char kSingleFS[] = "void main() { gl_FragColor = vec4(1, 0, 0, 1); }"; + ANGLE_GL_PROGRAM(singleProgram, kSingleVS, kSingleFS); - const std::string dualVertexShader = + constexpr char kDualVS[] = "#version 300 es\n" "in vec4 position;\n" "in vec4 color;\n" @@ -770,7 +769,7 @@ TEST_P(StateChangeTestES3, VertexArrayObjectAndDisabledAttributes) " gl_Position = position;\n" " varyColor = color;\n" "}"; - const std::string dualFragmentShader = + constexpr char kDualFS[] = "#version 300 es\n" "precision mediump float;\n" "in vec4 varyColor;\n" @@ -779,7 +778,7 @@ TEST_P(StateChangeTestES3, VertexArrayObjectAndDisabledAttributes) "{\n" " colorOut = varyColor;\n" "}"; - ANGLE_GL_PROGRAM(dualProgram, dualVertexShader, dualFragmentShader); + ANGLE_GL_PROGRAM(dualProgram, kDualVS, kDualFS); GLint positionLocation = glGetAttribLocation(dualProgram, "position"); ASSERT_NE(-1, positionLocation); GLint colorLocation = glGetAttribLocation(dualProgram, "color"); diff --git a/src/tests/gl_tests/SwizzleTest.cpp b/src/tests/gl_tests/SwizzleTest.cpp index 5b72af223..8393907f6 100644 --- a/src/tests/gl_tests/SwizzleTest.cpp +++ b/src/tests/gl_tests/SwizzleTest.cpp @@ -64,28 +64,26 @@ class SwizzleTest : public ANGLETest { ANGLETest::SetUp(); - const std::string vertexShaderSource = - R"(precision highp float; - attribute vec4 position; - varying vec2 texcoord; + constexpr char kVS[] = R"(precision highp float; +attribute vec4 position; +varying vec2 texcoord; - void main() - { - gl_Position = position; - texcoord = (position.xy * 0.5) + 0.5; - })"; +void main() +{ + gl_Position = position; + texcoord = (position.xy * 0.5) + 0.5; +})"; - const std::string fragmentShaderSource = - R"(precision highp float; - uniform sampler2D tex; - varying vec2 texcoord; + constexpr char kFS[] = R"(precision highp float; +uniform sampler2D tex; +varying vec2 texcoord; - void main() - { - gl_FragColor = texture2D(tex, texcoord); - })"; +void main() +{ + gl_FragColor = texture2D(tex, texcoord); +})"; - mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); mTextureUniformLocation = glGetUniformLocation(mProgram, "tex"); @@ -210,7 +208,7 @@ class SwizzleIntegerTest : public SwizzleTest { ANGLETest::SetUp(); - const std::string vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "precision highp float;\n" "in vec4 position;\n" @@ -222,7 +220,7 @@ class SwizzleIntegerTest : public SwizzleTest " texcoord = (position.xy * 0.5) + 0.5;\n" "}\n"; - const std::string fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "precision highp usampler2D;\n" @@ -240,7 +238,7 @@ class SwizzleIntegerTest : public SwizzleTest " my_FragColor = vec4(s) / 255.0;\n" "}\n"; - mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); mTextureUniformLocation = glGetUniformLocation(mProgram, "tex"); diff --git a/src/tests/gl_tests/TextureMultisampleTest.cpp b/src/tests/gl_tests/TextureMultisampleTest.cpp index b008e9caa..d61ac3b02 100644 --- a/src/tests/gl_tests/TextureMultisampleTest.cpp +++ b/src/tests/gl_tests/TextureMultisampleTest.cpp @@ -574,30 +574,28 @@ TEST_P(TextureMultisampleArrayWebGLTest, BindMultisampleArrayTextureWithoutExten // not enabled. TEST_P(TextureMultisampleArrayWebGLTest, ShaderWithoutExtension) { - const std::string &fragmentShaderRequireExtension = R"(#version 310 es - #extension GL_OES_texture_storage_multisample_2d_array : require - out highp vec4 my_FragColor; + constexpr char kFSRequiresExtension[] = R"(#version 310 es +#extension GL_OES_texture_storage_multisample_2d_array : require +out highp vec4 my_FragColor; - void main() { - my_FragColor = vec4(0.0); - } - )"; +void main() { + my_FragColor = vec4(0.0); +})"; - GLuint program = CompileProgram(essl31_shaders::vs::Simple(), fragmentShaderRequireExtension); + GLuint program = CompileProgram(essl31_shaders::vs::Simple(), kFSRequiresExtension); EXPECT_EQ(0u, program); - const std::string &fragmentShaderEnableAndUseExtension = R"(#version 310 es - #extension GL_OES_texture_storage_multisample_2d_array : enable + constexpr char kFSEnableAndUseExtension[] = R"(#version 310 es +#extension GL_OES_texture_storage_multisample_2d_array : enable - uniform highp sampler2DMSArray tex; - out highp ivec4 outSize; +uniform highp sampler2DMSArray tex; +out highp ivec4 outSize; - void main() { - outSize = ivec4(textureSize(tex), 0); - } - )"; +void main() { + outSize = ivec4(textureSize(tex), 0); +})"; - program = CompileProgram(essl31_shaders::vs::Simple(), fragmentShaderEnableAndUseExtension); + program = CompileProgram(essl31_shaders::vs::Simple(), kFSEnableAndUseExtension); EXPECT_EQ(0u, program); } @@ -878,18 +876,17 @@ TEST_P(TextureMultisampleArrayWebGLTest, TextureSizeInShader) { ANGLE_SKIP_TEST_IF(!requestArrayExtension()); - const std::string &fragmentShader = R"(#version 310 es - #extension GL_OES_texture_storage_multisample_2d_array : require + constexpr char kFS[] = R"(#version 310 es +#extension GL_OES_texture_storage_multisample_2d_array : require - uniform highp sampler2DMSArray tex; - out highp vec4 my_FragColor; +uniform highp sampler2DMSArray tex; +out highp vec4 my_FragColor; - void main() { - my_FragColor = (textureSize(tex) == ivec3(8, 4, 2)) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); - } - )"; +void main() { + my_FragColor = (textureSize(tex) == ivec3(8, 4, 2)) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1); +})"; - ANGLE_GL_PROGRAM(texSizeProgram, essl31_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(texSizeProgram, essl31_shaders::vs::Simple(), kFS); GLint texLocation = glGetUniformLocation(texSizeProgram, "tex"); ASSERT_GE(texLocation, 0); diff --git a/src/tests/gl_tests/TextureRectangleTest.cpp b/src/tests/gl_tests/TextureRectangleTest.cpp index edda57e92..d0b998cf0 100644 --- a/src/tests/gl_tests/TextureRectangleTest.cpp +++ b/src/tests/gl_tests/TextureRectangleTest.cpp @@ -289,7 +289,7 @@ TEST_P(TextureRectangleTest, SamplingFromRectangleESSL1) glTexImage2D(GL_TEXTURE_RECTANGLE_ANGLE, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green); - const std::string fs = + constexpr char kFS[] = "#extension GL_ARB_texture_rectangle : require\n" "precision mediump float;\n" "uniform sampler2DRect tex;\n" @@ -298,7 +298,7 @@ TEST_P(TextureRectangleTest, SamplingFromRectangleESSL1) " gl_FragColor = texture2DRect(tex, vec2(0, 0));\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), fs); + ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS); glUseProgram(program); GLint location = glGetUniformLocation(program, "tex"); @@ -322,7 +322,7 @@ TEST_P(TextureRectangleTestES3, SamplingFromRectangleESSL3) glTexImage2D(GL_TEXTURE_RECTANGLE_ANGLE, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &GLColor::green); - const std::string fs = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_ARB_texture_rectangle : require\n" "precision mediump float;\n" @@ -333,7 +333,7 @@ TEST_P(TextureRectangleTestES3, SamplingFromRectangleESSL3) " fragColor = texture(tex, vec2(0, 0));\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fs); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); glUseProgram(program); GLint location = glGetUniformLocation(program, "tex"); diff --git a/src/tests/gl_tests/TextureTest.cpp b/src/tests/gl_tests/TextureTest.cpp index 7e7a3cd8b..14464c959 100644 --- a/src/tests/gl_tests/TextureTest.cpp +++ b/src/tests/gl_tests/TextureTest.cpp @@ -47,26 +47,25 @@ class TexCoordDrawTest : public ANGLETest setConfigAlphaBits(8); } - virtual std::string getVertexShaderSource() + virtual const char *getVertexShaderSource() { - return - R"(precision highp float; - attribute vec4 position; - varying vec2 texcoord; + return R"(precision highp float; +attribute vec4 position; +varying vec2 texcoord; - void main() - { - gl_Position = vec4(position.xy, 0.0, 1.0); - texcoord = (position.xy * 0.5) + 0.5; - })"; +void main() +{ + gl_Position = vec4(position.xy, 0.0, 1.0); + texcoord = (position.xy * 0.5) + 0.5; +})"; } - virtual std::string getFragmentShaderSource() = 0; + virtual const char *getFragmentShaderSource() = 0; virtual void setUpProgram() { - const std::string vertexShaderSource = getVertexShaderSource(); - const std::string fragmentShaderSource = getFragmentShaderSource(); + const char *vertexShaderSource = getVertexShaderSource(); + const char *fragmentShaderSource = getFragmentShaderSource(); mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); ASSERT_NE(0u, mProgram); @@ -135,17 +134,16 @@ class Texture2DTest : public TexCoordDrawTest protected: Texture2DTest() : TexCoordDrawTest(), mTexture2D(0), mTexture2DUniformLocation(-1) {} - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return - R"(precision highp float; - uniform sampler2D tex; - varying vec2 texcoord; + return R"(precision highp float; +uniform sampler2D tex; +varying vec2 texcoord; - void main() - { - gl_FragColor = texture2D(tex, texcoord); - })"; +void main() +{ + gl_FragColor = texture2D(tex, texcoord); +})"; } virtual const char *getTextureUniformName() { return "tex"; } @@ -327,31 +325,29 @@ class Texture2DTestES3 : public Texture2DTest protected: Texture2DTestES3() : Texture2DTest() {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { - return std::string( - "#version 300 es\n" - "out vec2 texcoord;\n" - "in vec4 position;\n" - "void main()\n" - "{\n" - " gl_Position = vec4(position.xy, 0.0, 1.0);\n" - " texcoord = (position.xy * 0.5) + 0.5;\n" - "}\n"); + return "#version 300 es\n" + "out vec2 texcoord;\n" + "in vec4 position;\n" + "void main()\n" + "{\n" + " gl_Position = vec4(position.xy, 0.0, 1.0);\n" + " texcoord = (position.xy * 0.5) + 0.5;\n" + "}\n"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp sampler2D tex;\n" - "in vec2 texcoord;\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " fragColor = texture(tex, texcoord);\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp sampler2D tex;\n" + "in vec2 texcoord;\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " fragColor = texture(tex, texcoord);\n" + "}\n"; } void SetUp() override @@ -366,33 +362,31 @@ class Texture2DIntegerAlpha1TestES3 : public Texture2DTest protected: Texture2DIntegerAlpha1TestES3() : Texture2DTest() {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { - return std::string( - "#version 300 es\n" - "out vec2 texcoord;\n" - "in vec4 position;\n" - "void main()\n" - "{\n" - " gl_Position = vec4(position.xy, 0.0, 1.0);\n" - " texcoord = (position.xy * 0.5) + 0.5;\n" - "}\n"); + return "#version 300 es\n" + "out vec2 texcoord;\n" + "in vec4 position;\n" + "void main()\n" + "{\n" + " gl_Position = vec4(position.xy, 0.0, 1.0);\n" + " texcoord = (position.xy * 0.5) + 0.5;\n" + "}\n"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp isampler2D tex;\n" - "in vec2 texcoord;\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " vec4 green = vec4(0, 1, 0, 1);\n" - " vec4 black = vec4(0, 0, 0, 0);\n" - " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp isampler2D tex;\n" + "in vec2 texcoord;\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " vec4 green = vec4(0, 1, 0, 1);\n" + " vec4 black = vec4(0, 0, 0, 0);\n" + " fragColor = (texture(tex, texcoord).a == 1) ? green : black;\n" + "}\n"; } void SetUp() override @@ -407,33 +401,31 @@ class Texture2DUnsignedIntegerAlpha1TestES3 : public Texture2DTest protected: Texture2DUnsignedIntegerAlpha1TestES3() : Texture2DTest() {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { - return std::string( - "#version 300 es\n" - "out vec2 texcoord;\n" - "in vec4 position;\n" - "void main()\n" - "{\n" - " gl_Position = vec4(position.xy, 0.0, 1.0);\n" - " texcoord = (position.xy * 0.5) + 0.5;\n" - "}\n"); + return "#version 300 es\n" + "out vec2 texcoord;\n" + "in vec4 position;\n" + "void main()\n" + "{\n" + " gl_Position = vec4(position.xy, 0.0, 1.0);\n" + " texcoord = (position.xy * 0.5) + 0.5;\n" + "}\n"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp usampler2D tex;\n" - "in vec2 texcoord;\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " vec4 green = vec4(0, 1, 0, 1);\n" - " vec4 black = vec4(0, 0, 0, 0);\n" - " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp usampler2D tex;\n" + "in vec2 texcoord;\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " vec4 green = vec4(0, 1, 0, 1);\n" + " vec4 black = vec4(0, 0, 0, 0);\n" + " fragColor = (texture(tex, texcoord).a == 1u) ? green : black;\n" + "}\n"; } void SetUp() override @@ -448,7 +440,7 @@ class Texture2DTestWithDrawScale : public Texture2DTest protected: Texture2DTestWithDrawScale() : Texture2DTest(), mDrawScaleUniformLocation(-1) {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { return R"(precision highp float; @@ -487,7 +479,7 @@ class Sampler2DAsFunctionParameterTest : public Texture2DTest protected: Sampler2DAsFunctionParameterTest() : Texture2DTest() {} - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { return R"(precision highp float; @@ -523,7 +515,7 @@ class TextureCubeTest : public TexCoordDrawTest mTextureCubeUniformLocation(-1) {} - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { return R"(precision highp float; @@ -590,7 +582,7 @@ class SamplerArrayTest : public TexCoordDrawTest mTexture1UniformLocation(-1) {} - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { return R"(precision mediump float; @@ -664,7 +656,7 @@ class SamplerArrayAsFunctionParameterTest : public SamplerArrayTest protected: SamplerArrayAsFunctionParameterTest() : SamplerArrayTest() {} - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { return R"(precision mediump float; @@ -688,31 +680,29 @@ class Texture2DArrayTestES3 : public TexCoordDrawTest protected: Texture2DArrayTestES3() : TexCoordDrawTest(), m2DArrayTexture(0), mTextureArrayLocation(-1) {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { - return std::string( - "#version 300 es\n" - "out vec2 texcoord;\n" - "in vec4 position;\n" - "void main()\n" - "{\n" - " gl_Position = vec4(position.xy, 0.0, 1.0);\n" - " texcoord = (position.xy * 0.5) + 0.5;\n" - "}\n"); + return "#version 300 es\n" + "out vec2 texcoord;\n" + "in vec4 position;\n" + "void main()\n" + "{\n" + " gl_Position = vec4(position.xy, 0.0, 1.0);\n" + " texcoord = (position.xy * 0.5) + 0.5;\n" + "}\n"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp sampler2DArray tex2DArray;\n" - "in vec2 texcoord;\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp sampler2DArray tex2DArray;\n" + "in vec2 texcoord;\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " fragColor = texture(tex2DArray, vec3(texcoord.x, texcoord.y, 0.0));\n" + "}\n"; } void SetUp() override @@ -749,24 +739,20 @@ class TextureSizeTextureArrayTest : public TexCoordDrawTest mTexture1Location(-1) {} - std::string getVertexShaderSource() override - { - return std::string(essl3_shaders::vs::Simple()); - } + const char *getVertexShaderSource() override { return essl3_shaders::vs::Simple(); } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp sampler2D tex2DArray[2];\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n" - " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n" - " fragColor = vec4(red, green, 0.0, 1.0);\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp sampler2D tex2DArray[2];\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " float red = float(textureSize(tex2DArray[0], 0).x) / 255.0;\n" + " float green = float(textureSize(tex2DArray[1], 0).x) / 255.0;\n" + " fragColor = vec4(red, green, 0.0, 1.0);\n" + "}\n"; } void SetUp() override @@ -803,31 +789,29 @@ class Texture3DTestES3 : public TexCoordDrawTest protected: Texture3DTestES3() : TexCoordDrawTest(), mTexture3D(0), mTexture3DUniformLocation(-1) {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { - return std::string( - "#version 300 es\n" - "out vec2 texcoord;\n" - "in vec4 position;\n" - "void main()\n" - "{\n" - " gl_Position = vec4(position.xy, 0.0, 1.0);\n" - " texcoord = (position.xy * 0.5) + 0.5;\n" - "}\n"); + return "#version 300 es\n" + "out vec2 texcoord;\n" + "in vec4 position;\n" + "void main()\n" + "{\n" + " gl_Position = vec4(position.xy, 0.0, 1.0);\n" + " texcoord = (position.xy * 0.5) + 0.5;\n" + "}\n"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp sampler3D tex3D;\n" - "in vec2 texcoord;\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp sampler3D tex3D;\n" + "in vec2 texcoord;\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " fragColor = texture(tex3D, vec3(texcoord, 0.0));\n" + "}\n"; } void SetUp() override @@ -864,34 +848,32 @@ class ShadowSamplerPlusSampler3DTestES3 : public TexCoordDrawTest mDepthRefUniformLocation(-1) {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { - return std::string( - "#version 300 es\n" - "out vec2 texcoord;\n" - "in vec4 position;\n" - "void main()\n" - "{\n" - " gl_Position = vec4(position.xy, 0.0, 1.0);\n" - " texcoord = (position.xy * 0.5) + 0.5;\n" - "}\n"); + return "#version 300 es\n" + "out vec2 texcoord;\n" + "in vec4 position;\n" + "void main()\n" + "{\n" + " gl_Position = vec4(position.xy, 0.0, 1.0);\n" + " texcoord = (position.xy * 0.5) + 0.5;\n" + "}\n"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp sampler2DShadow tex2DShadow;\n" - "uniform highp sampler3D tex3D;\n" - "in vec2 texcoord;\n" - "uniform float depthRef;\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n" - " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp sampler2DShadow tex2DShadow;\n" + "uniform highp sampler3D tex3D;\n" + "in vec2 texcoord;\n" + "uniform float depthRef;\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " fragColor = vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.5);\n" + " fragColor += texture(tex3D, vec3(texcoord, 0.0));\n" + "}\n"; } void SetUp() override @@ -944,39 +926,37 @@ class SamplerTypeMixTestES3 : public TexCoordDrawTest mDepthRefUniformLocation(-1) {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { - return std::string( - "#version 300 es\n" - "out vec2 texcoord;\n" - "in vec4 position;\n" - "void main()\n" - "{\n" - " gl_Position = vec4(position.xy, 0.0, 1.0);\n" - " texcoord = (position.xy * 0.5) + 0.5;\n" - "}\n"); + return "#version 300 es\n" + "out vec2 texcoord;\n" + "in vec4 position;\n" + "void main()\n" + "{\n" + " gl_Position = vec4(position.xy, 0.0, 1.0);\n" + " texcoord = (position.xy * 0.5) + 0.5;\n" + "}\n"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp sampler2D tex2D;\n" - "uniform highp samplerCube texCube;\n" - "uniform highp sampler2DShadow tex2DShadow;\n" - "uniform highp samplerCubeShadow texCubeShadow;\n" - "in vec2 texcoord;\n" - "uniform float depthRef;\n" - "out vec4 fragColor;\n" - "void main()\n" - "{\n" - " fragColor = texture(tex2D, texcoord);\n" - " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n" - " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n" - " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * " - "0.125);\n" - "}\n"); + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp sampler2D tex2D;\n" + "uniform highp samplerCube texCube;\n" + "uniform highp sampler2DShadow tex2DShadow;\n" + "uniform highp samplerCubeShadow texCubeShadow;\n" + "in vec2 texcoord;\n" + "uniform float depthRef;\n" + "out vec4 fragColor;\n" + "void main()\n" + "{\n" + " fragColor = texture(tex2D, texcoord);\n" + " fragColor += texture(texCube, vec3(1.0, 0.0, 0.0));\n" + " fragColor += vec4(texture(tex2DShadow, vec3(texcoord, depthRef)) * 0.25);\n" + " fragColor += vec4(texture(texCubeShadow, vec4(1.0, 0.0, 0.0, depthRef)) * " + "0.125);\n" + "}\n"; } void SetUp() override @@ -1037,21 +1017,20 @@ class SamplerInStructTest : public Texture2DTest const char *getTextureUniformName() override { return "us.tex"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "precision highp float;\n" - "struct S\n" - "{\n" - " vec4 a;\n" - " highp sampler2D tex;\n" - "};\n" - "uniform S us;\n" - "varying vec2 texcoord;\n" - "void main()\n" - "{\n" - " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n" - "}\n"); + return "precision highp float;\n" + "struct S\n" + "{\n" + " vec4 a;\n" + " highp sampler2D tex;\n" + "};\n" + "uniform S us;\n" + "varying vec2 texcoord;\n" + "void main()\n" + "{\n" + " gl_FragColor = texture2D(us.tex, texcoord + us.a.x);\n" + "}\n"; } void runSamplerInStructTest() @@ -1072,24 +1051,23 @@ class SamplerInStructAsFunctionParameterTest : public SamplerInStructTest protected: SamplerInStructAsFunctionParameterTest() : SamplerInStructTest() {} - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "precision highp float;\n" - "struct S\n" - "{\n" - " vec4 a;\n" - " highp sampler2D tex;\n" - "};\n" - "uniform S us;\n" - "varying vec2 texcoord;\n" - "vec4 sampleFrom(S s) {\n" - " return texture2D(s.tex, texcoord + s.a.x);\n" - "}\n" - "void main()\n" - "{\n" - " gl_FragColor = sampleFrom(us);\n" - "}\n"); + return "precision highp float;\n" + "struct S\n" + "{\n" + " vec4 a;\n" + " highp sampler2D tex;\n" + "};\n" + "uniform S us;\n" + "varying vec2 texcoord;\n" + "vec4 sampleFrom(S s) {\n" + " return texture2D(s.tex, texcoord + s.a.x);\n" + "}\n" + "void main()\n" + "{\n" + " gl_FragColor = sampleFrom(us);\n" + "}\n"; } }; @@ -1100,24 +1078,23 @@ class SamplerInStructArrayAsFunctionParameterTest : public SamplerInStructTest const char *getTextureUniformName() override { return "us[0].tex"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "precision highp float;\n" - "struct S\n" - "{\n" - " vec4 a;\n" - " highp sampler2D tex;\n" - "};\n" - "uniform S us[1];\n" - "varying vec2 texcoord;\n" - "vec4 sampleFrom(S s) {\n" - " return texture2D(s.tex, texcoord + s.a.x);\n" - "}\n" - "void main()\n" - "{\n" - " gl_FragColor = sampleFrom(us[0]);\n" - "}\n"); + return "precision highp float;\n" + "struct S\n" + "{\n" + " vec4 a;\n" + " highp sampler2D tex;\n" + "};\n" + "uniform S us[1];\n" + "varying vec2 texcoord;\n" + "vec4 sampleFrom(S s) {\n" + " return texture2D(s.tex, texcoord + s.a.x);\n" + "}\n" + "void main()\n" + "{\n" + " gl_FragColor = sampleFrom(us[0]);\n" + "}\n"; } }; @@ -1128,28 +1105,27 @@ class SamplerInNestedStructAsFunctionParameterTest : public SamplerInStructTest const char *getTextureUniformName() override { return "us[0].sub.tex"; } - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "precision highp float;\n" - "struct SUB\n" - "{\n" - " vec4 a;\n" - " highp sampler2D tex;\n" - "};\n" - "struct S\n" - "{\n" - " SUB sub;\n" - "};\n" - "uniform S us[1];\n" - "varying vec2 texcoord;\n" - "vec4 sampleFrom(SUB s) {\n" - " return texture2D(s.tex, texcoord + s.a.x);\n" - "}\n" - "void main()\n" - "{\n" - " gl_FragColor = sampleFrom(us[0].sub);\n" - "}\n"); + return "precision highp float;\n" + "struct SUB\n" + "{\n" + " vec4 a;\n" + " highp sampler2D tex;\n" + "};\n" + "struct S\n" + "{\n" + " SUB sub;\n" + "};\n" + "uniform S us[1];\n" + "varying vec2 texcoord;\n" + "vec4 sampleFrom(SUB s) {\n" + " return texture2D(s.tex, texcoord + s.a.x);\n" + "}\n" + "void main()\n" + "{\n" + " gl_FragColor = sampleFrom(us[0].sub);\n" + "}\n"; } }; @@ -1158,22 +1134,21 @@ class SamplerInStructAndOtherVariableTest : public SamplerInStructTest protected: SamplerInStructAndOtherVariableTest() : SamplerInStructTest() {} - std::string getFragmentShaderSource() override + const char *getFragmentShaderSource() override { - return std::string( - "precision highp float;\n" - "struct S\n" - "{\n" - " vec4 a;\n" - " highp sampler2D tex;\n" - "};\n" - "uniform S us;\n" - "uniform float us_tex;\n" - "varying vec2 texcoord;\n" - "void main()\n" - "{\n" - " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n" - "}\n"); + return "precision highp float;\n" + "struct S\n" + "{\n" + " vec4 a;\n" + " highp sampler2D tex;\n" + "};\n" + "uniform S us;\n" + "uniform float us_tex;\n" + "varying vec2 texcoord;\n" + "void main()\n" + "{\n" + " gl_FragColor = texture2D(us.tex, texcoord + us.a.x + us_tex);\n" + "}\n"; } }; @@ -2761,7 +2736,7 @@ class TextureBorderClampTest : public Texture2DTest protected: TextureBorderClampTest() : Texture2DTest() {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { return R"(precision highp float; @@ -3012,7 +2987,7 @@ class TextureBorderClampIntegerTestES3 : public Texture2DTest protected: TextureBorderClampIntegerTestES3() : Texture2DTest(), isUnsignedIntTest(false) {} - std::string getVertexShaderSource() override + const char *getVertexShaderSource() override { return R"(#version 300 es @@ -3027,24 +3002,40 @@ class TextureBorderClampIntegerTestES3 : public Texture2DTest })"; } - std::string getFragmentShaderSource() + const char *getFragmentShaderSource() { - // clang-format off - return std::string( - "#version 300 es\n" - "precision highp float;\n" - "uniform highp ") + (isUnsignedIntTest ? "usampler2D" : "isampler2D") + " tex;\n" - "in vec2 texcoord;\n" - "out vec4 fragColor;\n" + if (isUnsignedIntTest) + { + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp usampler2D tex;\n" + "in vec2 texcoord;\n" + "out vec4 fragColor;\n" - "void main()\n" - "{\n" - "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n" - "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n" - "fragColor = (texture(tex, texcoord).r == " + (isUnsignedIntTest ? "150u" : "-50") + ")" - " ? green : red;\n" - "}\n"; - // clang-format on + "void main()\n" + "{\n" + "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n" + "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n" + "fragColor = (texture(tex, texcoord).r == 150u)" + " ? green : red;\n" + "}\n"; + } + else + { + return "#version 300 es\n" + "precision highp float;\n" + "uniform highp isampler2D tex;\n" + "in vec2 texcoord;\n" + "out vec4 fragColor;\n" + + "void main()\n" + "{\n" + "vec4 red = vec4(1.0, 0.0, 0.0, 1.0);\n" + "vec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n" + "fragColor = (texture(tex, texcoord).r == -50)" + " ? green : red;\n" + "}\n"; + } } void uploadTexture() @@ -3287,7 +3278,7 @@ class TextureLimitsTest : public ANGLETest const std::string &vertexShaderSource = vertexShaderStr.str(); const std::string &fragmentShaderSource = fragmentShaderStr.str(); - mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); + mProgram = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str()); } RGBA8 getPixel(GLint texIndex) @@ -3479,7 +3470,7 @@ TEST_P(TextureLimitsTest, MaxActiveFragmentTextures) // GLES 2.0.25 section 2.10.4 page 39. TEST_P(TextureLimitsTest, TextureTypeConflict) { - const std::string &vertexShader = + constexpr char kVS[] = "attribute vec2 position;\n" "varying float color;\n" "uniform sampler2D tex2D;\n" @@ -3490,13 +3481,13 @@ TEST_P(TextureLimitsTest, TextureTypeConflict) " color = texture2D(tex2D, texCoord).x;\n" " color += textureCube(texCube, vec3(texCoord, 0)).x;\n" "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "varying mediump float color;\n" "void main() {\n" " gl_FragColor = vec4(color, 0, 0, 1);\n" "}"; - mProgram = CompileProgram(vertexShader, fragmentShader); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); initTextures(1, 0); @@ -4034,7 +4025,7 @@ TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers) EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); // Simple multitexturing program. - const std::string vs = + constexpr char kVS[] = "#version 300 es\n" "in vec2 position;\n" "out vec2 texCoord;\n" @@ -4043,7 +4034,8 @@ TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers) " gl_Position = vec4(position, 0, 1);\n" " texCoord = position * 0.5 + vec2(0.5);\n" "}"; - const std::string fs = + + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "in vec2 texCoord;\n" @@ -4058,7 +4050,7 @@ TEST_P(Texture2DTestES3, SingleTextureMultipleSamplers) " + texture(tex3, texCoord) + texture(tex4, texCoord)) * 0.25;\n" "}"; - ANGLE_GL_PROGRAM(program, vs, fs); + ANGLE_GL_PROGRAM(program, kVS, kFS); std::array texLocations = { {glGetUniformLocation(program, "tex1"), glGetUniformLocation(program, "tex2"), @@ -4139,7 +4131,7 @@ TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1) // Check http://anglebug.com/2155. ANGLE_SKIP_TEST_IF(IsOSX() && IsNVIDIA()); - const std::string vs = + constexpr char kVS[] = R"(#version 300 es precision mediump float; in vec3 pos; @@ -4147,7 +4139,7 @@ TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1) gl_Position = vec4(pos, 1.0); })"; - const std::string fs = + constexpr char kFS[] = R"(#version 300 es precision mediump float; out vec4 color; @@ -4155,7 +4147,8 @@ TEST_P(TextureCubeTestES3, SpecifyAndSampleFromBaseLevel1) void main(){ color = texture(uTex, vec3(1.0)); })"; - ANGLE_GL_PROGRAM(program, vs, fs); + + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program); glUniform1i(glGetUniformLocation(program, "uTex"), 0); @@ -4241,7 +4234,7 @@ TEST_P(Texture2DTestES3, GenerateMipmapAndBaseLevelLUMA) // this led to not sampling your texture data when minification occurred. TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping) { - const std::string vs = + constexpr char kVS[] = "#version 300 es\n" "out vec2 texcoord;\n" "in vec4 position;\n" @@ -4251,7 +4244,7 @@ TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping) " texcoord = (position.xy * 0.5) + 0.5;\n" "}\n"; - const std::string fs = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "uniform highp sampler2D tex;\n" @@ -4261,7 +4254,8 @@ TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping) "{\n" " fragColor = texture(tex, texcoord);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vs, fs); + + ANGLE_GL_PROGRAM(program, kVS, kFS); GLSampler sampler; glBindSampler(0, sampler); diff --git a/src/tests/gl_tests/TimerQueriesTest.cpp b/src/tests/gl_tests/TimerQueriesTest.cpp index 9d45b6328..a607397ab 100644 --- a/src/tests/gl_tests/TimerQueriesTest.cpp +++ b/src/tests/gl_tests/TimerQueriesTest.cpp @@ -31,14 +31,14 @@ class TimerQueriesTest : public ANGLETest { ANGLETest::SetUp(); - const std::string costlyVS = + constexpr char kCostlyVS[] = "attribute highp vec4 position; varying highp vec4 testPos; void main(void)\n" "{\n" " testPos = position;\n" " gl_Position = position;\n" "}\n"; - const std::string costlyPS = + constexpr char kCostlyFS[] = "precision highp float; varying highp vec4 testPos; void main(void)\n" "{\n" " vec4 test = testPos;\n" @@ -52,7 +52,7 @@ class TimerQueriesTest : public ANGLETest mProgram = CompileProgram(essl1_shaders::vs::Simple(), essl1_shaders::fs::Red()); ASSERT_NE(0u, mProgram) << "shader compilation failed."; - mProgramCostly = CompileProgram(costlyVS, costlyPS); + mProgramCostly = CompileProgram(kCostlyVS, kCostlyFS); ASSERT_NE(0u, mProgramCostly) << "shader compilation failed."; } @@ -330,14 +330,14 @@ TEST_P(TimerQueriesTest, TimeElapsedMulticontextTest) }; ContextInfo contexts[2]; - const std::string costlyVS = + constexpr char kCostlyVS[] = "attribute highp vec4 position; varying highp vec4 testPos; void main(void)\n" "{\n" " testPos = position;\n" " gl_Position = position;\n" "}\n"; - const std::string costlyPS = + constexpr char kCostlyFS[] = "precision highp float; varying highp vec4 testPos; void main(void)\n" "{\n" " vec4 test = testPos;\n" @@ -362,7 +362,7 @@ TEST_P(TimerQueriesTest, TimeElapsedMulticontextTest) contexts[1].display = display; ASSERT_NE(contexts[1].context, EGL_NO_CONTEXT); eglMakeCurrent(display, surface, surface, contexts[1].context); - contexts[1].program = CompileProgram(costlyVS, costlyPS); + contexts[1].program = CompileProgram(kCostlyVS, kCostlyFS); glGenQueriesEXT(1, &contexts[1].query); ASSERT_GL_NO_ERROR(); diff --git a/src/tests/gl_tests/TransformFeedbackTest.cpp b/src/tests/gl_tests/TransformFeedbackTest.cpp index a024e0c4d..60ad8e05b 100644 --- a/src/tests/gl_tests/TransformFeedbackTest.cpp +++ b/src/tests/gl_tests/TransformFeedbackTest.cpp @@ -393,7 +393,7 @@ TEST_P(TransformFeedbackTest, BufferBinding) // Test that we can capture varyings only used in the vertex shader. TEST_P(TransformFeedbackTest, VertexOnly) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec2 position;\n" "in float attrib;\n" @@ -403,7 +403,7 @@ TEST_P(TransformFeedbackTest, VertexOnly) " varyingAttrib = attrib;\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "out mediump vec4 color;\n" "void main() {\n" @@ -413,8 +413,7 @@ TEST_P(TransformFeedbackTest, VertexOnly) std::vector tfVaryings; tfVaryings.push_back("varyingAttrib"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, mProgram); glUseProgram(mProgram); @@ -471,30 +470,27 @@ TEST_P(TransformFeedbackTest, MultiplePaused) const size_t transformFeedbackCount = 8; - const std::string vertexShaderSource = - R"(#version 300 es - in highp vec4 position; - in float transformFeedbackInput; - out float transformFeedbackOutput; - void main(void) - { - gl_Position = position; - transformFeedbackOutput = transformFeedbackInput; - })"; + constexpr char kVS[] = R"(#version 300 es +in highp vec4 position; +in float transformFeedbackInput; +out float transformFeedbackOutput; +void main(void) +{ + gl_Position = position; + transformFeedbackOutput = transformFeedbackInput; +})"; - const std::string fragmentShaderSource = - R"(#version 300 es - out mediump vec4 color; - void main(void) - { - color = vec4(1.0, 1.0, 1.0, 1.0); - })"; + constexpr char kFS[] = R"(#version 300 es +out mediump vec4 color; +void main(void) +{ + color = vec4(1.0, 1.0, 1.0, 1.0); +})"; std::vector tfVaryings; tfVaryings.push_back("transformFeedbackOutput"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, mProgram); glUseProgram(mProgram); @@ -590,37 +586,35 @@ TEST_P(TransformFeedbackTest, MultiContext) size_t bufferSize = maxDrawSize * passCount; std::vector bufferInitialData(bufferSize, 0); - for (auto &context : contexts) + constexpr char kVS[] = R"(#version 300 es +in highp vec4 position; +in float transformFeedbackInput; +out float transformFeedbackOutput; +void main(void) +{ + gl_Position = position; + transformFeedbackOutput = transformFeedbackInput; +})"; + + constexpr char kFS[] = R"(#version 300 es +out mediump vec4 color; +void main(void) +{ + color = vec4(1.0, 1.0, 1.0, 1.0); +})"; + + for (ContextInfo &context : contexts) { context.context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes); ASSERT_NE(context.context, EGL_NO_CONTEXT); eglMakeCurrent(display, surface, surface, context.context); - const std::string vertexShaderSource = - R"(#version 300 es - in highp vec4 position; - in float transformFeedbackInput; - out float transformFeedbackOutput; - void main(void) - { - gl_Position = position; - transformFeedbackOutput = transformFeedbackInput; - })"; - - const std::string fragmentShaderSource = - R"(#version 300 es - out mediump vec4 color; - void main(void) - { - color = vec4(1.0, 1.0, 1.0, 1.0); - })"; - std::vector tfVaryings; tfVaryings.push_back("transformFeedbackOutput"); - context.program = CompileProgramWithTransformFeedback( - vertexShaderSource, fragmentShaderSource, tfVaryings, GL_INTERLEAVED_ATTRIBS); + context.program = + CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(context.program, 0u); glUseProgram(context.program); @@ -724,7 +718,7 @@ TEST_P(TransformFeedbackTest, MultiContext) TEST_P(TransformFeedbackTest, PackingBug) { // TODO(jmadill): With points and rasterizer discard? - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec2 inAttrib1;\n" "in vec2 inAttrib2;\n" @@ -737,7 +731,7 @@ TEST_P(TransformFeedbackTest, PackingBug) " gl_Position = vec4(position, 0, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -749,8 +743,7 @@ TEST_P(TransformFeedbackTest, PackingBug) tfVaryings.push_back("outAttrib1"); tfVaryings.push_back("outAttrib2"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, mProgram); glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mTransformFeedbackBuffer); @@ -806,7 +799,7 @@ TEST_P(TransformFeedbackTest, PackingBug) // compilation to fail TEST_P(TransformFeedbackTest, OptimizedVaryings) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec4 a_vertex;\n" "in vec3 a_normal; \n" @@ -828,7 +821,7 @@ TEST_P(TransformFeedbackTest, OptimizedVaryings) " gl_Position = u_projectionMatrix * ecPosition;\n" "}\n"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "\n" @@ -846,8 +839,7 @@ TEST_P(TransformFeedbackTest, OptimizedVaryings) tfVaryings.push_back("normal"); tfVaryings.push_back("ecPosition"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, mProgram); } @@ -855,7 +847,7 @@ TEST_P(TransformFeedbackTest, OptimizedVaryings) TEST_P(TransformFeedbackTest, TwoUnreferencedInFragShader) { // TODO(jmadill): With points and rasterizer discard? - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec3 position;\n" "out vec3 outAttrib1;\n" @@ -866,7 +858,7 @@ TEST_P(TransformFeedbackTest, TwoUnreferencedInFragShader) " gl_Position = vec4(position, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -880,8 +872,7 @@ TEST_P(TransformFeedbackTest, TwoUnreferencedInFragShader) tfVaryings.push_back("outAttrib1"); tfVaryings.push_back("outAttrib2"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, mProgram); glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mTransformFeedbackBuffer); @@ -924,7 +915,7 @@ TEST_P(TransformFeedbackTest, OffsetResetOnBeginTransformFeedback) ANGLE_SKIP_TEST_IF(IsAndroid()); - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec4 position;\n" "out vec4 outAttrib;\n" @@ -933,7 +924,7 @@ TEST_P(TransformFeedbackTest, OffsetResetOnBeginTransformFeedback) " gl_Position = vec4(0);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -944,8 +935,7 @@ TEST_P(TransformFeedbackTest, OffsetResetOnBeginTransformFeedback) std::vector tfVaryings; tfVaryings.push_back("outAttrib"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, mProgram); GLint positionLocation = glGetAttribLocation(mProgram, "position"); @@ -1134,7 +1124,7 @@ class TransformFeedbackTestES31 : public TransformFeedbackTestBase // Test that program link fails in case that transform feedback names including same array element. TEST_P(TransformFeedbackTestES31, SameArrayElementVaryings) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "in vec3 position;\n" "out vec3 outAttribs[3];\n" @@ -1145,7 +1135,7 @@ TEST_P(TransformFeedbackTestES31, SameArrayElementVaryings) " gl_Position = vec4(position, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -1158,15 +1148,14 @@ TEST_P(TransformFeedbackTestES31, SameArrayElementVaryings) tfVaryings.push_back("outAttribs"); tfVaryings.push_back("outAttribs[1]"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_EQ(0u, mProgram); } // Test that program link fails in case to capture array element on a non-array varying. TEST_P(TransformFeedbackTestES31, ElementCaptureOnNonArrayVarying) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "in vec3 position;\n" "out vec3 outAttrib;\n" @@ -1175,7 +1164,7 @@ TEST_P(TransformFeedbackTestES31, ElementCaptureOnNonArrayVarying) " gl_Position = vec4(position, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -1187,15 +1176,14 @@ TEST_P(TransformFeedbackTestES31, ElementCaptureOnNonArrayVarying) std::vector tfVaryings; tfVaryings.push_back("outAttrib[1]"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_EQ(0u, mProgram); } // Test that program link fails in case to capure an outbound array element. TEST_P(TransformFeedbackTestES31, CaptureOutboundElement) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "in vec3 position;\n" "out vec3 outAttribs[3];\n" @@ -1206,7 +1194,7 @@ TEST_P(TransformFeedbackTestES31, CaptureOutboundElement) " gl_Position = vec4(position, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -1218,15 +1206,14 @@ TEST_P(TransformFeedbackTestES31, CaptureOutboundElement) std::vector tfVaryings; tfVaryings.push_back("outAttribs[3]"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_EQ(0u, mProgram); } // Test transform feedback names can be specified using array element. TEST_P(TransformFeedbackTestES31, DifferentArrayElementVaryings) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "in vec3 position;\n" "out vec3 outAttribs[3];\n" @@ -1237,7 +1224,7 @@ TEST_P(TransformFeedbackTestES31, DifferentArrayElementVaryings) " gl_Position = vec4(position, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -1250,8 +1237,7 @@ TEST_P(TransformFeedbackTestES31, DifferentArrayElementVaryings) tfVaryings.push_back("outAttribs[0]"); tfVaryings.push_back("outAttribs[2]"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, mProgram); glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mTransformFeedbackBuffer); @@ -1289,46 +1275,41 @@ TEST_P(TransformFeedbackTestES31, DifferentArrayElementVaryings) // Test transform feedback varying for base-level members of struct. TEST_P(TransformFeedbackTestES31, StructMemberVaryings) { - const std::string &vertexShaderSource = - R"(#version 310 es + constexpr char kVS[] = R"(#version 310 es +in vec3 position; +struct S { + vec3 field0; + vec3 field1; + vec3 field2; +}; +out S s; - in vec3 position; - struct S { - vec3 field0; - vec3 field1; - vec3 field2; - }; - out S s; +void main() { + s.field0 = position; + s.field1 = vec3(0, 0, 0); + s.field2 = position; + gl_Position = vec4(position, 1); +})"; - void main() { - s.field0 = position; - s.field1 = vec3(0, 0, 0); - s.field2 = position; - gl_Position = vec4(position, 1); - })"; + constexpr char kFS[] = R"(#version 310 es +precision mediump float; +struct S { + vec3 field0; + vec3 field1; + vec3 field2; +}; +out vec4 color; +in S s; - const std::string &fragmentShaderSource = - R"(#version 310 es - - precision mediump float; - struct S { - vec3 field0; - vec3 field1; - vec3 field2; - }; - out vec4 color; - in S s; - - void main() { - color = vec4(s.field1, 1); - })"; +void main() { + color = vec4(s.field1, 1); +})"; std::vector tfVaryings; tfVaryings.push_back("s.field0"); tfVaryings.push_back("s.field2"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, mProgram); glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mTransformFeedbackBuffer); @@ -1366,42 +1347,37 @@ TEST_P(TransformFeedbackTestES31, StructMemberVaryings) // Test transform feedback varying for struct is not allowed. TEST_P(TransformFeedbackTestES31, InvalidStructVaryings) { - const std::string &vertexShaderSource = - R"(#version 310 es + constexpr char kVS[] = R"(#version 310 es +in vec3 position; +struct S { + vec3 field0; + vec3 field1; +}; +out S s; - in vec3 position; - struct S { - vec3 field0; - vec3 field1; - }; - out S s; +void main() { + s.field0 = position; + s.field1 = vec3(0, 0, 0); + gl_Position = vec4(position, 1); +})"; - void main() { - s.field0 = position; - s.field1 = vec3(0, 0, 0); - gl_Position = vec4(position, 1); - })"; + constexpr char kFS[] = R"(#version 310 es +precision mediump float; +struct S { + vec3 field0; + vec3 field1; +}; +out vec4 color; +in S s; - const std::string &fragmentShaderSource = - R"(#version 310 es - - precision mediump float; - struct S { - vec3 field0; - vec3 field1; - }; - out vec4 color; - in S s; - - void main() { - color = vec4(s.field1, 1); - })"; +void main() { + color = vec4(s.field1, 1); +})"; std::vector tfVaryings; tfVaryings.push_back("s"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_EQ(0u, mProgram); } @@ -1432,7 +1408,7 @@ TEST_P(TransformFeedbackTest, NonExistentTransformFeedbackVaryingWithGLPrefix) // GLSL ES. TEST_P(TransformFeedbackTest, VaryingReservedOpenGLName) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec3 position;\n" "out vec3 buffer;\n" @@ -1441,7 +1417,7 @@ TEST_P(TransformFeedbackTest, VaryingReservedOpenGLName) " gl_Position = vec4(position, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 color;\n" @@ -1453,8 +1429,7 @@ TEST_P(TransformFeedbackTest, VaryingReservedOpenGLName) std::vector tfVaryings; tfVaryings.push_back("buffer"); - mProgram = CompileProgramWithTransformFeedback(vertexShaderSource, fragmentShaderSource, - tfVaryings, GL_INTERLEAVED_ATTRIBS); + mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_INTERLEAVED_ATTRIBS); ASSERT_NE(0u, mProgram); glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mTransformFeedbackBuffer); diff --git a/src/tests/gl_tests/UniformBufferTest.cpp b/src/tests/gl_tests/UniformBufferTest.cpp index 9787085aa..6d23c437a 100644 --- a/src/tests/gl_tests/UniformBufferTest.cpp +++ b/src/tests/gl_tests/UniformBufferTest.cpp @@ -29,17 +29,16 @@ class UniformBufferTest : public ANGLETest { ANGLETest::SetUp(); - mFragmentShaderSource = - R"(#version 300 es - precision highp float; - uniform uni { vec4 color; }; - out vec4 fragColor; - void main() - { - fragColor = color; - })"; + mkFS = R"(#version 300 es +precision highp float; +uniform uni { vec4 color; }; +out vec4 fragColor; +void main() +{ + fragColor = color; +})"; - mProgram = CompileProgram(essl3_shaders::vs::Simple(), mFragmentShaderSource); + mProgram = CompileProgram(essl3_shaders::vs::Simple(), mkFS); ASSERT_NE(mProgram, 0u); mUniformBufferIndex = glGetUniformBlockIndex(mProgram, "uni"); @@ -57,7 +56,7 @@ class UniformBufferTest : public ANGLETest ANGLETest::TearDown(); } - std::string mFragmentShaderSource; + const char *mkFS; GLuint mProgram; GLint mUniformBufferIndex; GLuint mUniformBuffer; @@ -323,7 +322,7 @@ TEST_P(UniformBufferTest, ManyUniformBufferRange) // Tests that active uniforms have the right names. TEST_P(UniformBufferTest, ActiveUniformNames) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec2 position;\n" "out vec2 v;\n" @@ -338,7 +337,7 @@ TEST_P(UniformBufferTest, ActiveUniformNames) " gl_Position = vec4(position, 0, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "in vec2 v;\n" @@ -347,8 +346,7 @@ TEST_P(UniformBufferTest, ActiveUniformNames) " color = vec4(v, 0, 1);\n" "}"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); - ASSERT_NE(0u, program); + ANGLE_GL_PROGRAM(program, kVS, kFS); GLint activeUniformBlocks; glGetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCKS, &activeUniformBlocks); @@ -397,7 +395,7 @@ TEST_P(UniformBufferTest, ActiveUniformNames) // Tests active uniforms and blocks when the layout is std140, shared and packed. TEST_P(UniformBufferTest, ActiveUniformNumberAndName) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 300 es\n" "in vec2 position;\n" "out float v;\n" @@ -426,7 +424,7 @@ TEST_P(UniformBufferTest, ActiveUniformNumberAndName) " gl_Position = vec4(position, 0, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "in float v;\n" @@ -435,7 +433,7 @@ TEST_P(UniformBufferTest, ActiveUniformNumberAndName) " color = vec4(v, 0, 0, 1);\n" "}"; - ANGLE_GL_PROGRAM(program, vertexShaderSource, fragmentShaderSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); // Note that the packed |blockName3| might (or might not) be optimized out. GLint activeUniforms; @@ -650,21 +648,21 @@ TEST_P(UniformBufferTest31, MaxUniformBufferBindingsExceeded) "{\n" " gl_Position = position;\n" "}"; - GLuint shader = CompileShader(GL_VERTEX_SHADER, source); + GLuint shader = CompileShader(GL_VERTEX_SHADER, source.c_str()); EXPECT_EQ(0u, shader); } // Test uniform block bindings specified by layout in shader work properly. TEST_P(UniformBufferTest31, UniformBufferBindings) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "in vec4 position;\n" "void main()\n" "{\n" " gl_Position = position;\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "precision highp float;\n" "layout(binding = 2) uniform uni {\n" @@ -676,7 +674,7 @@ TEST_P(UniformBufferTest31, UniformBufferBindings) " fragColor = color;\n" "}"; - ANGLE_GL_PROGRAM(program, vertexShaderSource, fragmentShaderSource); + ANGLE_GL_PROGRAM(program, kVS, kFS); GLuint uniformBufferIndex = glGetUniformBlockIndex(program, "uni"); ASSERT_NE(GL_INVALID_INDEX, uniformBufferIndex); GLBuffer uniformBuffer; @@ -722,7 +720,7 @@ TEST_P(UniformBufferTest31, UniformBufferBindings) // Test uniform blocks used as instanced array take next binding point for each subsequent element. TEST_P(UniformBufferTest31, ConsecutiveBindingsForBlockArray) { - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "precision highp float;\n" "layout(binding = 2) uniform uni {\n" @@ -734,7 +732,7 @@ TEST_P(UniformBufferTest31, ConsecutiveBindingsForBlockArray) " fragColor = blocks[0].color + blocks[1].color;\n" "}"; - ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), fragmentShaderSource); + ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Simple(), kFS); std::array uniformBuffers; int px = getWindowWidth() / 2; @@ -770,7 +768,7 @@ TEST_P(UniformBufferTest31, ConsecutiveBindingsForBlockArray) // Test the layout qualifier binding must be both specified(ESSL 3.10.4 section 9.2). TEST_P(UniformBufferTest31, BindingMustBeBothSpecified) { - const std::string &vertexShaderSource = + constexpr char kVS[] = "#version 310 es\n" "in vec4 position;\n" "uniform uni\n" @@ -781,7 +779,7 @@ TEST_P(UniformBufferTest31, BindingMustBeBothSpecified) "{\n" " gl_Position = position + block.color;\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFS[] = "#version 310 es\n" "precision highp float;\n" "layout(binding = 0) uniform uni\n" @@ -793,14 +791,14 @@ TEST_P(UniformBufferTest31, BindingMustBeBothSpecified) "{\n" " fragColor = block.color;\n" "}"; - GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource); + GLuint program = CompileProgram(kVS, kFS); ASSERT_EQ(0u, program); } // Test with a block containing an array of structs. TEST_P(UniformBufferTest, BlockContainingArrayOfStructs) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 my_FragColor;\n" @@ -823,7 +821,7 @@ TEST_P(UniformBufferTest, BlockContainingArrayOfStructs) " my_FragColor = lighting;\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "lightData"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); @@ -848,7 +846,7 @@ TEST_P(UniformBufferTest, BlockContainingArrayOfStructs) // Test with a block instance array containing an array of structs. TEST_P(UniformBufferTest, BlockArrayContainingArrayOfStructs) { - const std::string &fragmentShader = + constexpr char kFS[] = R"(#version 300 es precision highp float; @@ -872,7 +870,7 @@ TEST_P(UniformBufferTest, BlockArrayContainingArrayOfStructs) my_FragColor = lighting; })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "lightData[0]"); GLint uniformBuffer2Index = glGetUniformBlockIndex(program, "lightData[1]"); @@ -908,7 +906,7 @@ TEST_P(UniformBufferTest, BlockArrayContainingArrayOfStructs) // Test with a block containing an array of structs containing arrays. TEST_P(UniformBufferTest, BlockContainingArrayOfStructsContainingArrays) { - const std::string &fragmentShader = + constexpr char kFS[] = R"(#version 300 es precision highp float; out vec4 my_FragColor; @@ -930,7 +928,7 @@ TEST_P(UniformBufferTest, BlockContainingArrayOfStructsContainingArrays) my_FragColor = lighting; })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "lightData"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); @@ -956,7 +954,7 @@ TEST_P(UniformBufferTest, BlockContainingArrayOfStructsContainingArrays) // Test with a block containing nested structs. TEST_P(UniformBufferTest, BlockContainingNestedStructs) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 my_FragColor;\n" @@ -982,7 +980,7 @@ TEST_P(UniformBufferTest, BlockContainingNestedStructs) " my_FragColor = lighting;\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "lightData"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); @@ -1013,7 +1011,7 @@ TEST_P(UniformBufferTest, GetUniformBlockIndexDefaultReturn) // Block names can be reserved names in GLSL, as long as they're not reserved in GLSL ES. TEST_P(UniformBufferTest, UniformBlockReservedOpenGLName) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 my_FragColor;\n" @@ -1023,7 +1021,7 @@ TEST_P(UniformBufferTest, UniformBlockReservedOpenGLName) " my_FragColor = color;\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "buffer"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); @@ -1046,7 +1044,7 @@ TEST_P(UniformBufferTest, UniformBlockReservedOpenGLName) // Block instance names can be reserved names in GLSL, as long as they're not reserved in GLSL ES. TEST_P(UniformBufferTest, UniformBlockInstanceReservedOpenGLName) { - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out vec4 my_FragColor;\n" @@ -1056,7 +1054,7 @@ TEST_P(UniformBufferTest, UniformBlockInstanceReservedOpenGLName) " my_FragColor = buffer.color;\n" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "dmat2"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); @@ -1086,7 +1084,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockInstanceWithNestedStructsContainingV // http://anglebug.com/2217 ANGLE_SKIP_TEST_IF(IsAndroid() && !IsNVIDIA()); - const std::string &fragmentShader = + constexpr char kFS[] = R"(#version 300 es precision highp float; @@ -1113,7 +1111,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockInstanceWithNestedStructsContainingV accessStruct(buffer.s); })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "structBuffer"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); @@ -1141,19 +1139,19 @@ TEST_P(UniformBufferTest, DetachShaders) { GLuint vertexShader = CompileShader(GL_VERTEX_SHADER, essl3_shaders::vs::Simple()); ASSERT_NE(0u, vertexShader); - GLuint fragmentShader = CompileShader(GL_FRAGMENT_SHADER, mFragmentShaderSource); - ASSERT_NE(0u, fragmentShader); + GLuint kFS = CompileShader(GL_FRAGMENT_SHADER, mkFS); + ASSERT_NE(0u, kFS); GLuint program = glCreateProgram(); glAttachShader(program, vertexShader); - glAttachShader(program, fragmentShader); + glAttachShader(program, kFS); ASSERT_TRUE(LinkAttachedProgram(program)); glDetachShader(program, vertexShader); - glDetachShader(program, fragmentShader); + glDetachShader(program, kFS); glDeleteShader(vertexShader); - glDeleteShader(fragmentShader); + glDeleteShader(kFS); glClear(GL_COLOR_BUFFER_BIT); float floatData[4] = {0.5f, 0.75f, 0.25f, 1.0f}; @@ -1182,7 +1180,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockWithRowMajorQualifier) // http://anglebug.com/2273 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL()); - const std::string &fragmentShader = + constexpr char kFS[] = R"(#version 300 es precision highp float; @@ -1199,7 +1197,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockWithRowMajorQualifier) my_FragColor = vec4(buffer.m); })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "matrixBuffer"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); @@ -1230,7 +1228,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockWithPerMemberRowMajorQualifier) // http://anglebug.com/2273 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL()); - const std::string &fragmentShader = + constexpr char kFS[] = R"(#version 300 es precision highp float; @@ -1247,7 +1245,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockWithPerMemberRowMajorQualifier) my_FragColor = vec4(buffer.m); })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "matrixBuffer"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); @@ -1274,7 +1272,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockWithPerMemberRowMajorQualifier) // block is set as row-major. TEST_P(UniformBufferTest, Std140UniformBlockWithPerMemberColumnMajorQualifier) { - const std::string &fragmentShader = + constexpr char kFS[] = R"(#version 300 es precision highp float; @@ -1292,7 +1290,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockWithPerMemberColumnMajorQualifier) my_FragColor = vec4(buffer.m); })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "matrixBuffer"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); @@ -1324,7 +1322,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockWithRowMajorQualifierOnStruct) // http://anglebug.com/2273 ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL()); - const std::string &fragmentShader = + constexpr char kFS[] = R"(#version 300 es precision highp float; @@ -1346,7 +1344,7 @@ TEST_P(UniformBufferTest, Std140UniformBlockWithRowMajorQualifierOnStruct) my_FragColor = vec4(buffer.s.m); })"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragmentShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); GLint uniformBufferIndex = glGetUniformBlockIndex(program, "matrixBuffer"); glBindBuffer(GL_UNIFORM_BUFFER, mUniformBuffer); diff --git a/src/tests/gl_tests/UniformTest.cpp b/src/tests/gl_tests/UniformTest.cpp index 1ede3be70..7581dc686 100644 --- a/src/tests/gl_tests/UniformTest.cpp +++ b/src/tests/gl_tests/UniformTest.cpp @@ -326,8 +326,8 @@ class UniformTest : public ANGLETest { ANGLETest::SetUp(); - const std::string &vertexShader = "void main() { gl_Position = vec4(1); }"; - const std::string &fragShader = + constexpr char kVS[] = "void main() { gl_Position = vec4(1); }"; + constexpr char kFS[] = "precision mediump float;\n" "uniform float uniF;\n" "uniform int uniI;\n" @@ -342,7 +342,7 @@ class UniformTest : public ANGLETest " gl_FragColor += vec4(uniBArr[3] ? 1.0 : 0.0);\n" "}"; - mProgram = CompileProgram(vertexShader, fragShader); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(mProgram, 0u); mUniformFLocation = glGetUniformLocation(mProgram, "uniF"); @@ -397,24 +397,21 @@ TEST_P(UniformTest, GetUniformNoCurrentProgram) TEST_P(UniformTest, UniformArrayLocations) { - const std::string vertexShader = - R"(precision mediump float; - uniform float uPosition[4]; - void main(void) - { - gl_Position = vec4(uPosition[0], uPosition[1], uPosition[2], uPosition[3]); - })"; + constexpr char kVS[] = R"(precision mediump float; +uniform float uPosition[4]; +void main(void) +{ + gl_Position = vec4(uPosition[0], uPosition[1], uPosition[2], uPosition[3]); +})"; - const std::string fragShader = - R"(precision mediump float; - uniform float uColor[4]; - void main(void) - { - gl_FragColor = vec4(uColor[0], uColor[1], uColor[2], uColor[3]); - })"; + constexpr char kFS[] = R"(precision mediump float; +uniform float uColor[4]; +void main(void) +{ + gl_FragColor = vec4(uColor[0], uColor[1], uColor[2], uColor[3]); +})"; - GLuint program = CompileProgram(vertexShader, fragShader); - ASSERT_NE(program, 0u); + ANGLE_GL_PROGRAM(program, kVS, kFS); // Array index zero should be equivalent to the un-indexed uniform EXPECT_NE(-1, glGetUniformLocation(program, "uPosition")); @@ -697,7 +694,7 @@ class UniformTestES3 : public ANGLETest // Test queries for transposed arrays of non-square matrix uniforms. TEST_P(UniformTestES3, TransposedMatrixArrayUniformStateQuery) { - const std::string &fragShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform mat3x2 uniMat3x2[5];\n" @@ -710,7 +707,7 @@ TEST_P(UniformTestES3, TransposedMatrixArrayUniformStateQuery) " color += vec4(uniMat3x2[4][0][0]);\n" "}"; - mProgram = CompileProgram(essl3_shaders::vs::Zero(), fragShader); + mProgram = CompileProgram(essl3_shaders::vs::Zero(), kFS); ASSERT_NE(mProgram, 0u); glUseProgram(mProgram); @@ -756,7 +753,7 @@ TEST_P(UniformTestES3, TransposedMatrixArrayUniformStateQuery) // Check that trying setting too many elements of an array doesn't overflow TEST_P(UniformTestES3, OverflowArray) { - const std::string &fragShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform float uniF[5];\n" @@ -770,7 +767,7 @@ TEST_P(UniformTestES3, OverflowArray) " color = vec4(uniMat3x2[4][0][0] + uniF[4]);\n" "}"; - mProgram = CompileProgram(essl3_shaders::vs::Zero(), fragShader); + mProgram = CompileProgram(essl3_shaders::vs::Zero(), kFS); ASSERT_NE(mProgram, 0u); glUseProgram(mProgram); @@ -805,20 +802,20 @@ TEST_P(UniformTestES3, OverflowArray) // Check setting a sampler uniform TEST_P(UniformTest, Sampler) { - const std::string &vertShader = + constexpr char kVS[] = "uniform sampler2D tex2D;\n" "void main() {\n" " gl_Position = vec4(0, 0, 0, 1);\n" "}"; - const std::string &fragShader = + constexpr char kFS[] = "precision mediump float;\n" "uniform sampler2D tex2D;\n" "void main() {\n" " gl_FragColor = texture2D(tex2D, vec2(0, 0));\n" "}"; - ANGLE_GL_PROGRAM(program, vertShader, fragShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); GLint location = glGetUniformLocation(program.get(), "tex2D"); ASSERT_NE(-1, location); @@ -892,7 +889,7 @@ TEST_P(UniformTest, SamplerUniformsAppearOnce) // Renderer doesn't support vertex texture fetch, skipping test. ANGLE_SKIP_TEST_IF(!maxVertexTextureImageUnits); - const std::string &vertShader = + constexpr char kVS[] = "attribute vec2 position;\n" "uniform sampler2D tex2D;\n" "varying vec4 color;\n" @@ -901,7 +898,7 @@ TEST_P(UniformTest, SamplerUniformsAppearOnce) " color = texture2D(tex2D, vec2(0));\n" "}"; - const std::string &fragShader = + constexpr char kFS[] = "precision mediump float;\n" "varying vec4 color;\n" "uniform sampler2D tex2D;\n" @@ -909,8 +906,7 @@ TEST_P(UniformTest, SamplerUniformsAppearOnce) " gl_FragColor = texture2D(tex2D, vec2(0)) + color;\n" "}"; - GLuint program = CompileProgram(vertShader, fragShader); - ASSERT_NE(0u, program); + ANGLE_GL_PROGRAM(program, kVS, kFS); GLint activeUniformsCount = 0; glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &activeUniformsCount); @@ -1004,15 +1000,15 @@ TEST_P(UniformTestES3, ReturnsOnlyOneArrayElement) } } - const std::string &vertexShader = "#version 300 es\n" + uniformStream.str() + - "void main()\n" - "{\n" - " gl_Position = vec4(1.0" + - additionStream.str() + - ");\n" - "}"; + const std::string vertexShader = "#version 300 es\n" + uniformStream.str() + + "void main()\n" + "{\n" + " gl_Position = vec4(1.0" + + additionStream.str() + + ");\n" + "}"; - const std::string &fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 color;\n" @@ -1021,7 +1017,7 @@ TEST_P(UniformTestES3, ReturnsOnlyOneArrayElement) " color = vec4(1, 0, 0, 1);\n" "}"; - mProgram = CompileProgram(vertexShader, fragmentShader); + mProgram = CompileProgram(vertexShader.c_str(), kFS); ASSERT_NE(0u, mProgram); glUseProgram(mProgram); @@ -1119,7 +1115,7 @@ class UniformTestES31 : public ANGLETest // ESSL 3.10.4 section 4.4.3. TEST_P(UniformTestES31, StructLocationLayoutQualifier) { - const std::string &fragShader = + constexpr char kFS[] = "#version 310 es\n" "out highp vec4 my_FragColor;\n" "struct S\n" @@ -1133,7 +1129,7 @@ TEST_P(UniformTestES31, StructLocationLayoutQualifier) " my_FragColor = vec4(uS.f, uS.f2, 0, 1);\n" "}"; - ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Zero(), fragShader); + ANGLE_GL_PROGRAM(program, essl31_shaders::vs::Zero(), kFS); EXPECT_EQ(12, glGetUniformLocation(program.get(), "uS.f")); EXPECT_EQ(13, glGetUniformLocation(program.get(), "uS.f2")); @@ -1143,7 +1139,7 @@ TEST_P(UniformTestES31, StructLocationLayoutQualifier) // the vertex shader, but doesn't have a location specified there. TEST_P(UniformTestES31, UniformLocationInFragmentShader) { - const std::string &vertShader = + constexpr char kVS[] = "#version 310 es\n" "uniform highp sampler2D tex2D;\n" "void main()\n" @@ -1151,7 +1147,7 @@ TEST_P(UniformTestES31, UniformLocationInFragmentShader) " gl_Position = texture(tex2D, vec2(0));\n" "}"; - const std::string &fragShader = + constexpr char kFS[] = "#version 310 es\n" "precision mediump float;\n" "out vec4 my_FragColor;\n" @@ -1161,7 +1157,7 @@ TEST_P(UniformTestES31, UniformLocationInFragmentShader) " my_FragColor = texture(tex2D, vec2(0));\n" "}"; - ANGLE_GL_PROGRAM(program, vertShader, fragShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); EXPECT_EQ(12, glGetUniformLocation(program.get(), "tex2D")); } @@ -1171,7 +1167,7 @@ TEST_P(UniformTestES31, UniformLocationInFragmentShader) // same location, even if they are unused, otherwise a compiler or linker error will be generated." TEST_P(UniformTestES31, UnusedUniformsConflictingLocation) { - const std::string &vertShader = + constexpr char kVS[] = "#version 310 es\n" "uniform layout(location=12) highp sampler2D texA;\n" "void main()\n" @@ -1179,7 +1175,7 @@ TEST_P(UniformTestES31, UnusedUniformsConflictingLocation) " gl_Position = vec4(0);\n" "}"; - const std::string &fragShader = + constexpr char kFS[] = "#version 310 es\n" "out highp vec4 my_FragColor;\n" "uniform layout(location=12) highp sampler2D texB;\n" @@ -1188,7 +1184,7 @@ TEST_P(UniformTestES31, UnusedUniformsConflictingLocation) " my_FragColor = vec4(0);\n" "}"; - mProgram = CompileProgram(vertShader, fragShader); + mProgram = CompileProgram(kVS, kFS); EXPECT_EQ(0u, mProgram); } @@ -1198,7 +1194,7 @@ TEST_P(UniformTestES31, UnusedUniformsConflictingLocation) // same location, even if they are unused, otherwise a compiler or linker error will be generated." TEST_P(UniformTestES31, UnusedUniformArraysConflictingLocation) { - const std::string &vertShader = + constexpr char kVS[] = "#version 310 es\n" "uniform layout(location=11) highp vec4 uA[2];\n" "void main()\n" @@ -1206,7 +1202,7 @@ TEST_P(UniformTestES31, UnusedUniformArraysConflictingLocation) " gl_Position = vec4(0);\n" "}"; - const std::string &fragShader = + constexpr char kFS[] = "#version 310 es\n" "out highp vec4 my_FragColor;\n" "uniform layout(location=12) highp vec4 uB;\n" @@ -1215,7 +1211,7 @@ TEST_P(UniformTestES31, UnusedUniformArraysConflictingLocation) " my_FragColor = vec4(0);\n" "}"; - mProgram = CompileProgram(vertShader, fragShader); + mProgram = CompileProgram(kVS, kFS); EXPECT_EQ(0u, mProgram); } @@ -1223,7 +1219,7 @@ TEST_P(UniformTestES31, UnusedUniformArraysConflictingLocation) // Minimal test case for a bug revealed by dEQP tests. TEST_P(UniformTestES3, StructWithNonSquareMatrixAndBool) { - const std::string &fragShader = + constexpr char kFS[] = "#version 300 es\n" "precision highp float;\n" "out highp vec4 my_color;\n" @@ -1239,7 +1235,7 @@ TEST_P(UniformTestES3, StructWithNonSquareMatrixAndBool) " if (!uni.b) { my_color.g = 0.0; }" "}\n"; - ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), fragShader); + ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Simple(), kFS); glUseProgram(program.get()); @@ -1256,14 +1252,14 @@ TEST_P(UniformTestES3, StructWithNonSquareMatrixAndBool) // Test that uniforms with reserved OpenGL names that aren't reserved in GL ES 2 work correctly. TEST_P(UniformTest, UniformWithReservedOpenGLName) { - const char *fragShader = + constexpr char kFS[] = "precision mediump float;\n" "uniform float buffer;" "void main() {\n" " gl_FragColor = vec4(buffer);\n" "}"; - mProgram = CompileProgram(essl1_shaders::vs::Simple(), fragShader); + mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS); ASSERT_NE(mProgram, 0u); GLint location = glGetUniformLocation(mProgram, "buffer"); diff --git a/src/tests/gl_tests/UnpackAlignmentTest.cpp b/src/tests/gl_tests/UnpackAlignmentTest.cpp index 6deb3caef..ce5876c98 100644 --- a/src/tests/gl_tests/UnpackAlignmentTest.cpp +++ b/src/tests/gl_tests/UnpackAlignmentTest.cpp @@ -31,15 +31,13 @@ class UnpackAlignmentTest : public ANGLETest { ANGLETest::SetUp(); - const std::string fragmentShaderSource = - R"(uniform sampler2D tex; + constexpr char kFS[] = R"(uniform sampler2D tex; +void main() +{ + gl_FragColor = texture2D(tex, vec2(0.0, 1.0)); +})"; - void main() - { - gl_FragColor = texture2D(tex, vec2(0.0, 1.0)); - })"; - - mProgram = CompileProgram(essl1_shaders::vs::Simple(), fragmentShaderSource); + mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS); if (mProgram == 0) { FAIL() << "shader compilation failed."; diff --git a/src/tests/gl_tests/UnpackRowLength.cpp b/src/tests/gl_tests/UnpackRowLength.cpp index 19f43f624..6479cfe24 100644 --- a/src/tests/gl_tests/UnpackRowLength.cpp +++ b/src/tests/gl_tests/UnpackRowLength.cpp @@ -31,15 +31,13 @@ class UnpackRowLengthTest : public ANGLETest { ANGLETest::SetUp(); - const std::string fragmentShaderSource = - R"(uniform sampler2D tex; + constexpr char kFS[] = R"(uniform sampler2D tex; +void main() +{ + gl_FragColor = texture2D(tex, vec2(0.0, 1.0)); +})"; - void main() - { - gl_FragColor = texture2D(tex, vec2(0.0, 1.0)); - })"; - - mProgram = CompileProgram(essl1_shaders::vs::Simple(), fragmentShaderSource); + mProgram = CompileProgram(essl1_shaders::vs::Simple(), kFS); if (mProgram == 0) { FAIL() << "shader compilation failed."; diff --git a/src/tests/gl_tests/VertexAttributeTest.cpp b/src/tests/gl_tests/VertexAttributeTest.cpp index 9623e64cf..3c914d001 100644 --- a/src/tests/gl_tests/VertexAttributeTest.cpp +++ b/src/tests/gl_tests/VertexAttributeTest.cpp @@ -227,14 +227,14 @@ class VertexAttributeTest : public ANGLETest } shaderStream << "}" << std::endl; - constexpr char testFragmentShaderSource[] = + constexpr char kFS[] = "varying mediump float color;\n" "void main(void)\n" "{\n" " gl_FragColor = vec4(color, 0.0, 0.0, 1.0);\n" "}\n"; - return CompileProgram(shaderStream.str(), testFragmentShaderSource); + return CompileProgram(shaderStream.str().c_str(), kFS); } void setupMultiAttribs(GLuint program, GLint attribCount, GLfloat value) @@ -253,7 +253,7 @@ class VertexAttributeTest : public ANGLETest void initBasicProgram() { - constexpr char testVertexShaderSource[] = + constexpr char kVS[] = "attribute mediump vec4 position;\n" "attribute mediump vec4 test;\n" "attribute mediump vec4 expected;\n" @@ -265,14 +265,14 @@ class VertexAttributeTest : public ANGLETest " color = vec4(lessThanEqual(abs(test - expected), threshold));\n" "}\n"; - constexpr char testFragmentShaderSource[] = + constexpr char kFS[] = "varying mediump vec4 color;\n" "void main(void)\n" "{\n" " gl_FragColor = color;\n" "}\n"; - mProgram = CompileProgram(testVertexShaderSource, testFragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); mTestAttrib = glGetAttribLocation(mProgram, "test"); @@ -953,7 +953,7 @@ TEST_P(VertexAttributeTest, DisabledAttribArrays) // TODO: Support this test on Vulkan. http://anglebug.com/2797 ANGLE_SKIP_TEST_IF(IsLinux() && IsVulkan() && IsIntel()); - constexpr char vsSource[] = + constexpr char kVS[] = "attribute vec4 a_position;\n" "attribute vec4 a_color;\n" "varying vec4 v_color;\n" @@ -965,7 +965,7 @@ TEST_P(VertexAttributeTest, DisabledAttribArrays) " v_color = isCorrectColor(a_color) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n" "}"; - constexpr char fsSource[] = + constexpr char kFS[] = "varying mediump vec4 v_color;\n" "void main() {\n" " gl_FragColor = v_color;\n" @@ -976,7 +976,7 @@ TEST_P(VertexAttributeTest, DisabledAttribArrays) for (GLint colorIndex = 0; colorIndex < maxVertexAttribs; ++colorIndex) { - GLuint program = CompileProgram(vsSource, fsSource, [&](GLuint program) { + GLuint program = CompileProgram(kVS, kFS, [&](GLuint program) { glBindAttribLocation(program, colorIndex, "a_color"); }); ASSERT_NE(0u, program); @@ -1467,7 +1467,7 @@ class VertexAttributeCachingTest : public VertexAttributeTest void initDoubleAttribProgram() { - constexpr char testVertexShaderSource[] = + constexpr char kVS[] = "attribute mediump vec4 position;\n" "attribute mediump vec4 test;\n" "attribute mediump vec4 expected;\n" @@ -1483,14 +1483,14 @@ class VertexAttributeCachingTest : public VertexAttributeTest " color += vec4(lessThanEqual(abs(test2 - expected2), threshold2));\n" "}\n"; - constexpr char testFragmentShaderSource[] = + constexpr char kFS[] = "varying mediump vec4 color;\n" "void main(void)\n" "{\n" " gl_FragColor = color;\n" "}\n"; - mProgram = CompileProgram(testVertexShaderSource, testFragmentShaderSource); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); mTestAttrib = glGetAttribLocation(mProgram, "test"); diff --git a/src/tests/gl_tests/WebGLCompatibilityTest.cpp b/src/tests/gl_tests/WebGLCompatibilityTest.cpp index 225bf352c..f14d933e5 100644 --- a/src/tests/gl_tests/WebGLCompatibilityTest.cpp +++ b/src/tests/gl_tests/WebGLCompatibilityTest.cpp @@ -85,7 +85,7 @@ class WebGLCompatibilityTest : public ANGLETest { ASSERT_GL_NO_ERROR(); - const std::string samplingVs = + constexpr char kVS[] = "attribute vec4 position;\n" "varying vec2 texcoord;\n" "void main()\n" @@ -94,7 +94,7 @@ class WebGLCompatibilityTest : public ANGLETest " texcoord = (position.xy * 0.5) + 0.5;\n" "}\n"; - const std::string samplingFs = + constexpr char kFS[] = "precision mediump float;\n" "uniform sampler2D tex;\n" "uniform vec4 subtractor;\n" @@ -115,7 +115,7 @@ class WebGLCompatibilityTest : public ANGLETest " }\n" "}\n"; - ANGLE_GL_PROGRAM(samplingProgram, samplingVs, samplingFs); + ANGLE_GL_PROGRAM(samplingProgram, kVS, kFS); glUseProgram(samplingProgram.get()); // Need RGBA8 renderbuffers for enough precision on the readback @@ -319,10 +319,10 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionStandardDerivitives) { EXPECT_FALSE(extensionEnabled("GL_OES_standard_derivatives")); - const std::string source = + constexpr char kFS[] = "#extension GL_OES_standard_derivatives : require\n" "void main() { gl_FragColor = vec4(dFdx(vec2(1.0, 1.0)).x, 1, 0, 1); }\n"; - ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source)); + ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, kFS)); if (extensionRequestable("GL_OES_standard_derivatives")) { @@ -330,7 +330,7 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionStandardDerivitives) EXPECT_GL_NO_ERROR(); EXPECT_TRUE(extensionEnabled("GL_OES_standard_derivatives")); - GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); + GLuint shader = CompileShader(GL_FRAGMENT_SHADER, kFS); ASSERT_NE(0u, shader); glDeleteShader(shader); } @@ -341,14 +341,14 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionTextureLOD) { EXPECT_FALSE(extensionEnabled("GL_EXT_shader_texture_lod")); - const std::string source = + constexpr char kFS[] = "#extension GL_EXT_shader_texture_lod : require\n" "uniform sampler2D u_texture;\n" "void main() {\n" " gl_FragColor = texture2DGradEXT(u_texture, vec2(0.0, 0.0), vec2(0.0, 0.0), vec2(0.0, " "0.0));\n" "}\n"; - ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source)); + ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, kFS)); if (extensionRequestable("GL_EXT_shader_texture_lod")) { @@ -356,7 +356,7 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionTextureLOD) EXPECT_GL_NO_ERROR(); EXPECT_TRUE(extensionEnabled("GL_EXT_shader_texture_lod")); - GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); + GLuint shader = CompileShader(GL_FRAGMENT_SHADER, kFS); ASSERT_NE(0u, shader); glDeleteShader(shader); } @@ -367,13 +367,13 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionFragDepth) { EXPECT_FALSE(extensionEnabled("GL_EXT_frag_depth")); - const std::string source = + constexpr char kFS[] = "#extension GL_EXT_frag_depth : require\n" "void main() {\n" " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n" " gl_FragDepthEXT = 1.0;\n" "}\n"; - ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source)); + ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, kFS)); if (extensionRequestable("GL_EXT_frag_depth")) { @@ -381,7 +381,7 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionFragDepth) EXPECT_GL_NO_ERROR(); EXPECT_TRUE(extensionEnabled("GL_EXT_frag_depth")); - GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); + GLuint shader = CompileShader(GL_FRAGMENT_SHADER, kFS); ASSERT_NE(0u, shader); glDeleteShader(shader); } @@ -434,7 +434,7 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionEGLImage) EXPECT_FALSE(extensionEnabled("GL_OES_EGL_image_external_essl3")); EXPECT_FALSE(extensionEnabled("NV_EGL_stream_consumer_external")); - const std::string &fragES2 = + constexpr char kFSES2[] = "#extension GL_OES_EGL_image_external : require\n" "precision highp float;\n" "uniform samplerExternalOES sampler;\n" @@ -442,9 +442,9 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionEGLImage) "{\n" " gl_FragColor = texture2D(sampler, vec2(0, 0));\n" "}"; - EXPECT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, fragES2)); + EXPECT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, kFSES2)); - const std::string &fragES3 = + constexpr char kFSES3[] = "#version 300 es\n" "#extension GL_OES_EGL_image_external : require\n" "precision highp float;\n" @@ -455,7 +455,7 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionEGLImage) "}"; if (getClientMajorVersion() > 3) { - EXPECT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, fragES3)); + EXPECT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, kFSES3)); } glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0); @@ -471,7 +471,7 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionEGLImage) EXPECT_GL_NO_ERROR(); EXPECT_TRUE(extensionEnabled("GL_OES_EGL_image_external")); - EXPECT_NE(0u, CompileShader(GL_FRAGMENT_SHADER, fragES2)); + EXPECT_NE(0u, CompileShader(GL_FRAGMENT_SHADER, kFSES2)); glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0); EXPECT_GL_NO_ERROR(); @@ -485,11 +485,11 @@ TEST_P(WebGLCompatibilityTest, EnableExtensionEGLImage) EXPECT_GL_NO_ERROR(); EXPECT_TRUE(extensionEnabled("GL_OES_EGL_image_external_essl3")); - EXPECT_NE(0u, CompileShader(GL_FRAGMENT_SHADER, fragES3)); + EXPECT_NE(0u, CompileShader(GL_FRAGMENT_SHADER, kFSES3)); } else { - EXPECT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, fragES3)); + EXPECT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, kFSES3)); } } } @@ -500,7 +500,7 @@ TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec) EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility")); // Use of reserved _webgl prefix should fail when the shader specification is for WebGL. - const std::string &vert = + constexpr char kVS[] = "struct Foo {\n" " int _webgl_bar;\n" "};\n" @@ -510,13 +510,13 @@ TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec) "}"; // Default fragement shader. - const std::string &frag = + constexpr char kFS[] = "void main()\n" "{\n" " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n" "}"; - GLuint program = CompileProgram(vert, frag); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); glDeleteProgram(program); } @@ -1043,18 +1043,18 @@ TEST_P(WebGLCompatibilityTest, EnableProgramBinaryExtension) glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, &result); EXPECT_GL_ERROR(GL_INVALID_ENUM); - const std::string &vert = + constexpr char kVS[] = "void main()\n" "{\n" " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n" "}\n"; - const std::string &frag = + constexpr char kFS[] = "precision highp float;\n" "void main()\n" "{\n" " gl_FragColor = vec4(1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, frag); + ANGLE_GL_PROGRAM(program, kVS, kFS); glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &result); EXPECT_GL_ERROR(GL_INVALID_ENUM); @@ -1180,21 +1180,21 @@ TEST_P(WebGLCompatibilityTest, FramebufferAttachmentSizeMismatch) // Test that client-side array buffers are forbidden in WebGL mode TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer) { - const std::string &vert = + constexpr char kVS[] = "attribute vec3 a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, 1.0);\n" "}\n"; - const std::string &frag = + constexpr char kFS[] = "precision highp float;\n" "void main()\n" "{\n" " gl_FragColor = vec4(1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, frag); + ANGLE_GL_PROGRAM(program, kVS, kFS); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); ASSERT_NE(-1, posLocation); @@ -1212,21 +1212,21 @@ TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer) // Test that client-side element array buffers are forbidden in WebGL mode TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer) { - const std::string &vert = + constexpr char kVS[] = "attribute vec3 a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, 1.0);\n" "}\n"; - const std::string &frag = + constexpr char kFS[] = "precision highp float;\n" "void main()\n" "{\n" " gl_FragColor = vec4(1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, frag); + ANGLE_GL_PROGRAM(program, kVS, kFS); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); ASSERT_NE(-1, posLocation); @@ -1254,20 +1254,20 @@ TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer) // Test that client-side array buffers are forbidden even if the program doesn't use the attribute TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBufferEvenNotUsedOnes) { - const std::string &vert = + constexpr char kVS[] = "void main()\n" "{\n" " gl_Position = vec4(1.0);\n" "}\n"; - const std::string &frag = + constexpr char kFS[] = "precision highp float;\n" "void main()\n" "{\n" " gl_FragColor = vec4(1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, frag); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program.get()); @@ -1423,14 +1423,14 @@ TEST_P(WebGLCompatibilityTest, MaxStride) // Test the checks for OOB reads in the vertex buffers, non-instanced version TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced) { - const std::string &vert = + constexpr char kVS[] = "attribute float a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); ASSERT_NE(-1, posLocation); glUseProgram(program.get()); @@ -1480,14 +1480,14 @@ TEST_P(WebGLCompatibilityTest, LargeIndexRange) { ANGLE_SKIP_TEST_IF(!ensureExtensionEnabled("GL_OES_element_index_uint")); - const std::string &vert = + constexpr char kVS[] = "attribute vec4 a_Position;\n" "void main()\n" "{\n" " gl_Position = a_Position;\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); glUseProgram(program.get()); glEnableVertexAttribArray(glGetAttribLocation(program, "a_Position")); @@ -1526,14 +1526,14 @@ TEST_P(WebGLCompatibilityTest, LargeIndexRange) // Test for drawing with a null index buffer TEST_P(WebGLCompatibilityTest, NullIndexBuffer) { - const std::string &vert = + constexpr char kVS[] = "attribute float a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); glUseProgram(program.get()); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); @@ -1546,7 +1546,7 @@ TEST_P(WebGLCompatibilityTest, NullIndexBuffer) // Test the checks for OOB reads in the vertex buffers, instanced version TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced) { - const std::string &vert = + constexpr char kVS[] = "attribute float a_pos;\n" "attribute float a_w;\n" "void main()\n" @@ -1554,7 +1554,7 @@ TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced) " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); GLint wLocation = glGetAttribLocation(program.get(), "a_w"); ASSERT_NE(-1, posLocation); @@ -1612,7 +1612,7 @@ TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsInstancedANGLE) glRequestExtensionANGLE("GL_ANGLE_instanced_arrays"); EXPECT_GL_NO_ERROR(); - const std::string &vert = + constexpr char kVS[] = "attribute float a_pos;\n" "attribute float a_w;\n" "void main()\n" @@ -1620,7 +1620,7 @@ TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsInstancedANGLE) " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); GLint wLocation = glGetAttribLocation(program.get(), "a_w"); ASSERT_NE(-1, posLocation); @@ -1674,14 +1674,14 @@ TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsInstancedANGLE) // Test the checks for OOB reads in the index buffer TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer) { - const std::string &vert = + constexpr char kVS[] = "attribute float a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); ASSERT_NE(-1, posLocation); glUseProgram(program.get()); @@ -1727,14 +1727,14 @@ TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer) // Test the checks for OOB in vertex buffers caused by indices, non-instanced version TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInVertexBuffer) { - const std::string &vert = + constexpr char kVS[] = "attribute float a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); ASSERT_NE(-1, posLocation); glUseProgram(program.get()); @@ -1864,7 +1864,7 @@ TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames) " */gl_FragColor = vec4(1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, frag); + ANGLE_GL_PROGRAM(program, vert.c_str(), frag.c_str()); EXPECT_GL_NO_ERROR(); for (char invalidChar : invalidSet) @@ -1991,14 +1991,14 @@ TEST_P(WebGLCompatibilityTest, BindAttribLocationLimitation) // Test that having no attributes with a zero divisor is valid in WebGL2 TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor) { - const std::string &vert = + constexpr char kVS[] = "attribute float a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); ASSERT_NE(-1, posLocation); @@ -2077,7 +2077,7 @@ TEST_P(WebGLCompatibilityTest, DefaultPosition) // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set, // and green otherwise. The center of each quadrant will be red if and only if all // four corners are red. - const std::string vertexShader = + constexpr char kVS[] = "attribute vec3 pos;\n" "varying vec4 color;\n" "void main() {\n" @@ -2089,14 +2089,14 @@ TEST_P(WebGLCompatibilityTest, DefaultPosition) " gl_Position = vec4(pos,1);\n" "}\n"; - const std::string fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "varying vec4 color;\n" "void main() {\n" " gl_FragColor = color;\n" "}\n"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); drawQuad(program.get(), "pos", 0.0f, 1.0f, true); EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red); EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red); @@ -2108,7 +2108,7 @@ TEST_P(WebGLCompatibilityTest, DefaultPosition) // Based on WebGL test conformance/renderbuffers/feedback-loop.html. TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop) { - const std::string vertexShader = + constexpr char kVS[] = "attribute vec4 a_position;\n" "varying vec2 v_texCoord;\n" "void main() {\n" @@ -2116,7 +2116,7 @@ TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop) " v_texCoord = (a_position.xy * 0.5) + 0.5;\n" "}\n"; - const std::string fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "varying vec2 v_texCoord;\n" "uniform sampler2D u_texture;\n" @@ -2136,7 +2136,7 @@ TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop) ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture"); ASSERT_NE(-1, uniformLoc); @@ -2211,14 +2211,14 @@ TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints) // Test that the offset in the index buffer is forced to be a multiple of the element size TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction) { - const std::string &vert = + constexpr char kVS[] = "attribute vec3 a_pos;\n" "void main()\n" "{\n" " gl_Position = vec4(a_pos, 1.0);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Red()); GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); ASSERT_NE(-1, posLocation); @@ -2300,7 +2300,7 @@ void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program, // Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT) { - const std::string vertexShader = + constexpr char kVS[] = "attribute vec4 aPosition;\n" "varying vec2 texCoord;\n" "void main() {\n" @@ -2308,7 +2308,7 @@ TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT) " texCoord = (aPosition.xy * 0.5) + 0.5;\n" "}\n"; - const std::string fragmentShader = + constexpr char kFS[] = "#extension GL_EXT_draw_buffers : require\n" "precision mediump float;\n" "uniform sampler2D tex;\n" @@ -2336,7 +2336,7 @@ TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT) // Test skipped because MAX_DRAW_BUFFERS is too small. ANGLE_SKIP_TEST_IF(maxDrawBuffers < 2); - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program.get()); glViewport(0, 0, width, height); @@ -2446,30 +2446,30 @@ void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program, // Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html. TEST_P(WebGLCompatibilityTest, BuiltInInvariant) { - const std::string vertexShaderVariant = + constexpr char kVS[] = "varying vec4 v_varying;\n" "void main()\n" "{\n" " gl_PointSize = 1.0;\n" " gl_Position = v_varying;\n" "}"; - const std::string fragmentShaderInvariantGlFragCoord = + constexpr char kFSInvariantGlFragCoord[] = "invariant gl_FragCoord;\n" "void main()\n" "{\n" " gl_FragColor = gl_FragCoord;\n" "}"; - const std::string fragmentShaderInvariantGlPointCoord = + constexpr char kFSInvariantGlPointCoord[] = "invariant gl_PointCoord;\n" "void main()\n" "{\n" " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n" "}"; - GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord); + GLuint program = CompileProgram(kVS, kFSInvariantGlFragCoord); EXPECT_EQ(0u, program); - program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord); + program = CompileProgram(kVS, kFSInvariantGlPointCoord); EXPECT_EQ(0u, program); } @@ -2477,13 +2477,13 @@ TEST_P(WebGLCompatibilityTest, BuiltInInvariant) // Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html. TEST_P(WebGLCompatibilityTest, GlobalNamesConflict) { - const std::string vertexShader = + constexpr char kVS[] = "attribute vec4 foo;\n" "void main()\n" "{\n" " gl_Position = foo;\n" "}"; - const std::string fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "uniform vec4 foo;\n" "void main()\n" @@ -2491,7 +2491,7 @@ TEST_P(WebGLCompatibilityTest, GlobalNamesConflict) " gl_FragColor = foo;\n" "}"; - GLuint program = CompileProgram(vertexShader, fragmentShader); + GLuint program = CompileProgram(kVS, kFS); EXPECT_EQ(0u, program); } @@ -3175,7 +3175,7 @@ TEST_P(WebGLCompatibilityTest, FramebufferAttachmentConsistancy) // Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers) { - const std::string vertexShader = + constexpr char kVS[] = "#version 300 es\n" "in vec4 aPosition;\n" "out vec2 texCoord;\n" @@ -3184,7 +3184,7 @@ TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers) " texCoord = (aPosition.xy * 0.5) + 0.5;\n" "}\n"; - const std::string fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform sampler2D tex;\n" @@ -3202,7 +3202,7 @@ TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers) // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS. ASSERT_GE(maxDrawBuffers, 2); - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program.get()); glViewport(0, 0, width, height); @@ -3234,7 +3234,7 @@ TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers) // Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil) { - const std::string vertexShader = + constexpr char kVS[] = "#version 300 es\n" "in vec4 aPosition;\n" "out vec2 texCoord;\n" @@ -3243,7 +3243,7 @@ TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil) " texCoord = (aPosition.xy * 0.5) + 0.5;\n" "}\n"; - const std::string fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "uniform sampler2D tex;\n" @@ -3256,7 +3256,7 @@ TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil) GLsizei width = 8; GLsizei height = 8; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program.get()); glViewport(0, 0, width, height); @@ -3573,13 +3573,13 @@ TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage) // buffer types TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch) { - const std::string vertexShader = + constexpr char kVS[] = "#version 300 es\n" "void main() {\n" " gl_Position = vec4(0, 0, 0, 1);\n" "}\n"; - const std::string fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "layout(location = 0) out vec4 floatOutput;\n" @@ -3591,7 +3591,7 @@ TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch) " intOutput = ivec4(0, 0, 0, 1);\n" "}\n"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program.get()); GLuint floatLocation = glGetFragDataLocation(program, "floatOutput"); @@ -3665,7 +3665,7 @@ TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch) // types TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMismatch) { - const std::string vertexShader = + constexpr char kVS[] = "#version 300 es\n" "in vec4 floatInput;\n" "in uvec4 uintInput;\n" @@ -3674,7 +3674,7 @@ TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMismatch) " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n" "}\n"; - const std::string fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "precision mediump float;\n" "out vec4 outputColor;\n" @@ -3682,7 +3682,7 @@ TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMismatch) " outputColor = vec4(0, 0, 0, 1);" "}\n"; - ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); + ANGLE_GL_PROGRAM(program, kVS, kFS); glUseProgram(program.get()); GLint floatLocation = glGetAttribLocation(program, "floatInput"); @@ -4190,19 +4190,19 @@ TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionLossyDecode) // qualifiers. TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch) { - const std::string vertexShader = + constexpr char kVS[] = "#version 300 es\n" "uniform Block { mediump vec4 val; };\n" "void main() { gl_Position = val; }\n"; - const std::string fragmentShader = + constexpr char kFS[] = "#version 300 es\n" "uniform Block { highp vec4 val; };\n" "out highp vec4 out_FragColor;\n" "void main() { out_FragColor = val; }\n"; - GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader); + GLuint vs = CompileShader(GL_VERTEX_SHADER, kVS); ASSERT_NE(0u, vs); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, kFS); ASSERT_NE(0u, fs); GLuint program = glCreateProgram(); @@ -4223,7 +4223,7 @@ TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch) // Test no attribute vertex shaders TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader) { - const std::string vertexShader = + constexpr char kVS[] = "#version 300 es\n" "void main()\n" "{\n" @@ -4232,7 +4232,7 @@ TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader) " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n" "}"; - ANGLE_GL_PROGRAM(program, vertexShader, essl3_shaders::fs::Red()); + ANGLE_GL_PROGRAM(program, kVS, essl3_shaders::fs::Red()); glUseProgram(program); glDrawArrays(GL_TRIANGLES, 0, 6); diff --git a/src/tests/gl_tests/WebGLReadOutsideFramebufferTest.cpp b/src/tests/gl_tests/WebGLReadOutsideFramebufferTest.cpp index d882bd499..45f2c23c0 100644 --- a/src/tests/gl_tests/WebGLReadOutsideFramebufferTest.cpp +++ b/src/tests/gl_tests/WebGLReadOutsideFramebufferTest.cpp @@ -235,16 +235,14 @@ class WebGLReadOutsideFramebufferTest : public ANGLETest { ANGLETest::SetUp(); - // TODO(fjhenigman): Factor out this shader and others like it in other tests, into - // ANGLETest. - const std::string vertexShader = + constexpr char kVS[] = "attribute vec3 a_position;\n" "varying vec2 v_texCoord;\n" "void main() {\n" " v_texCoord = a_position.xy * 0.5 + 0.5;\n" " gl_Position = vec4(a_position, 1);\n" "}\n"; - const std::string fragmentShader = + constexpr char kFS[] = "precision mediump float;\n" "varying vec2 v_texCoord;\n" "uniform sampler2D u_texture;\n" @@ -252,7 +250,7 @@ class WebGLReadOutsideFramebufferTest : public ANGLETest " gl_FragColor = texture2D(u_texture, v_texCoord);\n" "}\n"; - mProgram = CompileProgram(vertexShader, fragmentShader); + mProgram = CompileProgram(kVS, kFS); glUseProgram(mProgram); GLint uniformLoc = glGetUniformLocation(mProgram, "u_texture"); ASSERT_NE(-1, uniformLoc); diff --git a/src/tests/perf_tests/ANGLEPerfTest.cpp b/src/tests/perf_tests/ANGLEPerfTest.cpp index a53ce3469..14056139b 100644 --- a/src/tests/perf_tests/ANGLEPerfTest.cpp +++ b/src/tests/perf_tests/ANGLEPerfTest.cpp @@ -9,9 +9,10 @@ #include "ANGLEPerfTest.h" -#include "system_utils.h" #include "third_party/perf/perf_test.h" #include "third_party/trace_event/trace_event.h" +#include "util/shader_utils.h" +#include "util/system_utils.h" #include #include diff --git a/src/tests/perf_tests/BindingPerf.cpp b/src/tests/perf_tests/BindingPerf.cpp index 23d53995a..5df3d7049 100644 --- a/src/tests/perf_tests/BindingPerf.cpp +++ b/src/tests/perf_tests/BindingPerf.cpp @@ -15,6 +15,8 @@ #include "shader_utils.h" +#include "angle_gl.h" + namespace angle { constexpr unsigned int kIterationsPerStep = 128; diff --git a/src/tests/perf_tests/DispatchComputePerf.cpp b/src/tests/perf_tests/DispatchComputePerf.cpp index 2c49e2992..5d2b287ca 100644 --- a/src/tests/perf_tests/DispatchComputePerf.cpp +++ b/src/tests/perf_tests/DispatchComputePerf.cpp @@ -10,6 +10,8 @@ #include "ANGLEPerfTest.h" #include "shader_utils.h" +#include "angle_gl.h" + namespace { unsigned int kIterationsPerStep = 50; @@ -94,22 +96,21 @@ void DispatchComputePerfBenchmark::initializeBenchmark() void DispatchComputePerfBenchmark::initComputeShader() { - const std::string &csSource = - R"(#version 310 es - #define LOCAL_SIZE_X 16 - #define LOCAL_SIZE_Y 16 - layout(local_size_x=LOCAL_SIZE_X, local_size_y=LOCAL_SIZE_Y) in; - precision highp float; - uniform sampler2D readTexture; - layout(r32f, binding = 4) writeonly uniform highp image2D outImage; + constexpr char kCS[] = R"(#version 310 es +#define LOCAL_SIZE_X 16 +#define LOCAL_SIZE_Y 16 +layout(local_size_x=LOCAL_SIZE_X, local_size_y=LOCAL_SIZE_Y) in; +precision highp float; +uniform sampler2D readTexture; +layout(r32f, binding = 4) writeonly uniform highp image2D outImage; - void main() { - float sum = 0.; - sum += texelFetch(readTexture, ivec2(gl_GlobalInvocationID.xy), 0).r; - imageStore(outImage, ivec2(gl_GlobalInvocationID.xy), vec4(sum)); - })"; +void main() { + float sum = 0.; + sum += texelFetch(readTexture, ivec2(gl_GlobalInvocationID.xy), 0).r; + imageStore(outImage, ivec2(gl_GlobalInvocationID.xy), vec4(sum)); +})"; - mProgram = CompileComputeProgram(csSource, false); + mProgram = CompileComputeProgram(kCS, false); ASSERT_NE(0u, mProgram); } diff --git a/src/tests/perf_tests/DynamicPromotionPerfTest.cpp b/src/tests/perf_tests/DynamicPromotionPerfTest.cpp index 19e2e3911..c007457a2 100644 --- a/src/tests/perf_tests/DynamicPromotionPerfTest.cpp +++ b/src/tests/perf_tests/DynamicPromotionPerfTest.cpp @@ -65,7 +65,7 @@ DynamicPromotionPerfTest::DynamicPromotionPerfTest() void DynamicPromotionPerfTest::initializeBenchmark() { - const std::string &vertexShaderSource = + constexpr char kVertexShaderSource[] = "attribute vec2 position;\n" "attribute vec3 color;\n" "varying vec3 vColor;\n" @@ -75,14 +75,14 @@ void DynamicPromotionPerfTest::initializeBenchmark() " gl_Position = vec4(position, 0, 1);\n" "}"; - const std::string &fragmentShaderSource = + constexpr char kFragmentShaderSource[] = "varying mediump vec3 vColor;\n" "void main()\n" "{\n" " gl_FragColor = vec4(vColor, 1);\n" "}"; - mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); + mProgram = CompileProgram(kVertexShaderSource, kFragmentShaderSource); ASSERT_NE(0u, mProgram); const size_t vertexCount = GetParam().vertexCount; diff --git a/src/tests/perf_tests/InstancingPerf.cpp b/src/tests/perf_tests/InstancingPerf.cpp index 1a3e76836..82c2882e2 100644 --- a/src/tests/perf_tests/InstancingPerf.cpp +++ b/src/tests/perf_tests/InstancingPerf.cpp @@ -109,7 +109,7 @@ void InstancingPerfBenchmark::initializeBenchmark() { const auto ¶ms = GetParam(); - const std::string vs = + const char kVS[] = "attribute vec2 aPosition;\n" "attribute vec3 aTranslate;\n" "attribute float aScale;\n" @@ -125,7 +125,7 @@ void InstancingPerfBenchmark::initializeBenchmark() " vColor = aColor;\n" "}\n"; - const std::string fs = + constexpr char kFS[] = "precision mediump float;\n" "varying vec3 vColor;\n" "void main()\n" @@ -133,7 +133,7 @@ void InstancingPerfBenchmark::initializeBenchmark() " gl_FragColor = vec4(vColor, 1.0);\n" "}\n"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); glUseProgram(mProgram); diff --git a/src/tests/perf_tests/InterleavedAttributeData.cpp b/src/tests/perf_tests/InterleavedAttributeData.cpp index 049a3a306..d58d406a4 100644 --- a/src/tests/perf_tests/InterleavedAttributeData.cpp +++ b/src/tests/perf_tests/InterleavedAttributeData.cpp @@ -78,7 +78,7 @@ void InterleavedAttributeDataBenchmark::initializeBenchmark() const auto ¶ms = GetParam(); // Compile point sprite shaders - const std::string vs = + constexpr char kVS[] = "attribute vec4 aPosition;" "attribute vec4 aColor;" "varying vec4 vColor;" @@ -89,7 +89,7 @@ void InterleavedAttributeDataBenchmark::initializeBenchmark() " vColor = aColor;" "}"; - const std::string fs = + constexpr char kFS[] = "precision mediump float;" "varying vec4 vColor;" "void main()" @@ -97,7 +97,7 @@ void InterleavedAttributeDataBenchmark::initializeBenchmark() " gl_FragColor = vColor;" "}"; - mPointSpriteProgram = CompileProgram(vs, fs); + mPointSpriteProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mPointSpriteProgram); glClearColor(0.0f, 1.0f, 0.0f, 1.0f); diff --git a/src/tests/perf_tests/MultiviewPerf.cpp b/src/tests/perf_tests/MultiviewPerf.cpp index cd7d062df..3671e1ea3 100644 --- a/src/tests/perf_tests/MultiviewPerf.cpp +++ b/src/tests/perf_tests/MultiviewPerf.cpp @@ -135,7 +135,7 @@ class MultiviewBenchmark : public ANGLERenderTest, protected: virtual void renderScene() = 0; - void createProgram(const std::string &vs, const std::string &fs) + void createProgram(const char *vs, const char *fs) { mProgram = CompileProgram(vs, fs); if (mProgram == 0) @@ -267,7 +267,7 @@ void MultiviewCPUBoundBenchmark::initializeBenchmark() const MultiviewPerfParams *params = static_cast(&mTestParams); const bool usesMultiview = (params->multiviewOption != MultiviewOption::NoAcceleration); - const std::string &vs = + const std::string vs = "#version 300 es\n" + GetShaderExtensionHeader(usesMultiview, params->numViews, GL_VERTEX_SHADER) + "layout(location=0) in vec4 vPosition;\n" @@ -279,7 +279,7 @@ void MultiviewCPUBoundBenchmark::initializeBenchmark() " gl_Position = v;\n" "}\n"; - const std::string &fs = + const std::string fs = "#version 300 es\n" + GetShaderExtensionHeader(usesMultiview, params->numViews, GL_FRAGMENT_SHADER) + "precision mediump float;\n" @@ -290,7 +290,7 @@ void MultiviewCPUBoundBenchmark::initializeBenchmark() " col = vec4(1.);\n" "}\n"; - createProgram(vs, fs); + createProgram(vs.c_str(), fs.c_str()); const float viewWidth = static_cast(params->windowWidth / params->numViews); const float viewHeight = static_cast(params->windowHeight); @@ -398,7 +398,7 @@ void MultiviewGPUBoundBenchmark::initializeBenchmark() " col += frag_Col5;\n" "}\n"; - createProgram(vs, fs); + createProgram(vs.c_str(), fs.c_str()); ASSERT_GL_NO_ERROR(); // Generate a vertex buffer of triangulated quads so that we have one quad per pixel. diff --git a/src/tests/perf_tests/PointSprites.cpp b/src/tests/perf_tests/PointSprites.cpp index 79907a174..6324d1380 100644 --- a/src/tests/perf_tests/PointSprites.cpp +++ b/src/tests/perf_tests/PointSprites.cpp @@ -137,7 +137,7 @@ void PointSpritesBenchmark::initializeBenchmark() fstrstr << " gl_FragColor = colorOut;\n" "}\n"; - mProgram = CompileProgram(vstrstr.str(), fstrstr.str()); + mProgram = CompileProgram(vstrstr.str().c_str(), fstrstr.str().c_str()); ASSERT_NE(0u, mProgram); // Use the program object diff --git a/src/tests/perf_tests/TexSubImage.cpp b/src/tests/perf_tests/TexSubImage.cpp index b7b7e1a09..42fb47153 100644 --- a/src/tests/perf_tests/TexSubImage.cpp +++ b/src/tests/perf_tests/TexSubImage.cpp @@ -131,26 +131,24 @@ void TexSubImageBenchmark::initializeBenchmark() { const auto ¶ms = GetParam(); - const std::string vs = - R"(attribute vec4 a_position; - attribute vec2 a_texCoord; - varying vec2 v_texCoord; - void main() - { - gl_Position = a_position; - v_texCoord = a_texCoord; - })"; + constexpr char kVS[] = R"(attribute vec4 a_position; +attribute vec2 a_texCoord; +varying vec2 v_texCoord; +void main() +{ + gl_Position = a_position; + v_texCoord = a_texCoord; +})"; - const std::string fs = - R"(precision mediump float; - varying vec2 v_texCoord; - uniform sampler2D s_texture; - void main() - { - gl_FragColor = texture2D(s_texture, v_texCoord); - })"; + constexpr char kFS[] = R"(precision mediump float; +varying vec2 v_texCoord; +uniform sampler2D s_texture; +void main() +{ + gl_FragColor = texture2D(s_texture, v_texCoord); +})"; - mProgram = CompileProgram(vs, fs); + mProgram = CompileProgram(kVS, kFS); ASSERT_NE(0u, mProgram); // Get the attribute locations diff --git a/src/tests/perf_tests/TextureSampling.cpp b/src/tests/perf_tests/TextureSampling.cpp index 4e8939110..a74b3a8fa 100644 --- a/src/tests/perf_tests/TextureSampling.cpp +++ b/src/tests/perf_tests/TextureSampling.cpp @@ -152,7 +152,7 @@ void TextureSamplingBenchmark::initShaders() fstrstr << " gl_FragColor = colorOut;\n" "}\n"; - mProgram = CompileProgram(vstrstr.str(), fstrstr.str()); + mProgram = CompileProgram(vstrstr.str().c_str(), fstrstr.str().c_str()); ASSERT_NE(0u, mProgram); // Use the program object diff --git a/src/tests/perf_tests/TexturesPerf.cpp b/src/tests/perf_tests/TexturesPerf.cpp index 79d3bfd09..75bbd5e59 100644 --- a/src/tests/perf_tests/TexturesPerf.cpp +++ b/src/tests/perf_tests/TexturesPerf.cpp @@ -151,7 +151,7 @@ void TexturesBenchmark::initShaders() fstrstr << ";\n" "}\n"; - mProgram = CompileProgram(vs, fstrstr.str()); + mProgram = CompileProgram(vs.c_str(), fstrstr.str().c_str()); ASSERT_NE(0u, mProgram); for (size_t i = 0; i < params.numTextures; ++i) diff --git a/src/tests/perf_tests/UniformsPerf.cpp b/src/tests/perf_tests/UniformsPerf.cpp index 9f6e86aac..6c12cfb1e 100644 --- a/src/tests/perf_tests/UniformsPerf.cpp +++ b/src/tests/perf_tests/UniformsPerf.cpp @@ -279,9 +279,9 @@ void UniformsBenchmark::initShaders() } fstrstr << "}"; - mPrograms[0] = CompileProgram(vstrstr.str(), fstrstr.str()); + mPrograms[0] = CompileProgram(vstrstr.str().c_str(), fstrstr.str().c_str()); ASSERT_NE(0u, mPrograms[0]); - mPrograms[1] = CompileProgram(vstrstr.str(), fstrstr.str()); + mPrograms[1] = CompileProgram(vstrstr.str().c_str(), fstrstr.str().c_str()); ASSERT_NE(0u, mPrograms[1]); for (size_t i = 0; i < params.numVertexUniforms; ++i) diff --git a/src/tests/test_utils/ANGLETest.cpp b/src/tests/test_utils/ANGLETest.cpp index b5f4bc495..38784b836 100644 --- a/src/tests/test_utils/ANGLETest.cpp +++ b/src/tests/test_utils/ANGLETest.cpp @@ -679,7 +679,7 @@ GLuint ANGLETestBase::get2DTexturedQuadProgram() return m2DTexturedQuadProgram; } - const std::string &vs = + constexpr char kVS[] = "attribute vec2 position;\n" "varying mediump vec2 texCoord;\n" "void main()\n" @@ -688,7 +688,7 @@ GLuint ANGLETestBase::get2DTexturedQuadProgram() " texCoord = position * 0.5 + vec2(0.5);\n" "}\n"; - const std::string &fs = + constexpr char kFS[] = "varying mediump vec2 texCoord;\n" "uniform sampler2D tex;\n" "void main()\n" @@ -696,7 +696,7 @@ GLuint ANGLETestBase::get2DTexturedQuadProgram() " gl_FragColor = texture2D(tex, texCoord);\n" "}\n"; - m2DTexturedQuadProgram = CompileProgram(vs, fs); + m2DTexturedQuadProgram = CompileProgram(kVS, kFS); return m2DTexturedQuadProgram; } @@ -707,32 +707,30 @@ GLuint ANGLETestBase::get3DTexturedQuadProgram() return m3DTexturedQuadProgram; } - const std::string &vs = - R"(#version 300 es - in vec2 position; - out vec2 texCoord; - void main() - { - gl_Position = vec4(position, 0, 1); - texCoord = position * 0.5 + vec2(0.5); - })"; + constexpr char kVS[] = R"(#version 300 es +in vec2 position; +out vec2 texCoord; +void main() +{ + gl_Position = vec4(position, 0, 1); + texCoord = position * 0.5 + vec2(0.5); +})"; - const std::string &fs = - R"(#version 300 es - precision highp float; + constexpr char kFS[] = R"(#version 300 es +precision highp float; - in vec2 texCoord; - out vec4 my_FragColor; +in vec2 texCoord; +out vec4 my_FragColor; - uniform highp sampler3D tex; - uniform float u_layer; +uniform highp sampler3D tex; +uniform float u_layer; - void main() - { - my_FragColor = texture(tex, vec3(texCoord, u_layer)); - })"; +void main() +{ + my_FragColor = texture(tex, vec3(texCoord, u_layer)); +})"; - m3DTexturedQuadProgram = CompileProgram(vs, fs); + m3DTexturedQuadProgram = CompileProgram(kVS, kFS); return m3DTexturedQuadProgram; } @@ -768,41 +766,6 @@ void ANGLETestBase::draw3DTexturedQuad(GLfloat positionAttribZ, } } -GLuint ANGLETestBase::compileShader(GLenum type, const std::string &source) -{ - GLuint shader = glCreateShader(type); - - const char *sourceArray[1] = {source.c_str()}; - glShaderSource(shader, 1, sourceArray, nullptr); - glCompileShader(shader); - - GLint compileResult; - glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult); - - if (compileResult == 0) - { - GLint infoLogLength; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength); - - if (infoLogLength == 0) - { - std::cerr << "shader compilation failed with empty log." << std::endl; - } - else - { - std::vector infoLog(infoLogLength); - glGetShaderInfoLog(shader, static_cast(infoLog.size()), nullptr, &infoLog[0]); - - std::cerr << "shader compilation failed: " << &infoLog[0] << std::endl; - } - - glDeleteShader(shader); - shader = 0; - } - - return shader; -} - void ANGLETestBase::checkD3D11SDKLayersMessages() { #if defined(ANGLE_PLATFORM_WINDOWS) diff --git a/src/tests/test_utils/ANGLETest.h b/src/tests/test_utils/ANGLETest.h index d9ebad65f..d80768aaa 100644 --- a/src/tests/test_utils/ANGLETest.h +++ b/src/tests/test_utils/ANGLETest.h @@ -319,7 +319,6 @@ class ANGLETestBase bool useVertexBuffer, float layer); - static GLuint compileShader(GLenum type, const std::string &source); static bool extensionEnabled(const std::string &extName); static bool extensionRequestable(const std::string &extName); static bool ensureExtensionEnabled(const std::string &extName); diff --git a/src/tests/test_utils/MultiviewTest.cpp b/src/tests/test_utils/MultiviewTest.cpp index 2ca80d74d..6d29e74b1 100644 --- a/src/tests/test_utils/MultiviewTest.cpp +++ b/src/tests/test_utils/MultiviewTest.cpp @@ -29,7 +29,7 @@ GLuint CreateSimplePassthroughProgram(int numViews) " gl_Position = vec4(vPosition.xy, 0.0, 1.0);\n" "}\n"; - const std::string fsSource = + constexpr char kFS[] = "#version 300 es\n" "#extension GL_OVR_multiview : require\n" "precision mediump float;\n" @@ -38,7 +38,7 @@ GLuint CreateSimplePassthroughProgram(int numViews) "{\n" " col = vec4(0,1,0,1);\n" "}\n"; - return CompileProgram(vsSource, fsSource); + return CompileProgram(vsSource.c_str(), kFS); } void CreateMultiviewBackingTextures(GLenum multiviewLayout, diff --git a/src/tests/test_utils/draw_call_perf_utils.cpp b/src/tests/test_utils/draw_call_perf_utils.cpp index e9feedb0f..a3f94f837 100644 --- a/src/tests/test_utils/draw_call_perf_utils.cpp +++ b/src/tests/test_utils/draw_call_perf_utils.cpp @@ -15,63 +15,44 @@ namespace { - -const char *SimpleScaleAndOffsetVertexShaderSource() +constexpr char kSimpleScaleAndOffsetVS[] = R"(attribute vec2 vPosition; +uniform float uScale; +uniform float uOffset; +void main() { - return - R"(attribute vec2 vPosition; - uniform float uScale; - uniform float uOffset; - void main() - { - gl_Position = vec4(vPosition * vec2(uScale) + vec2(uOffset), 0, 1); - })"; -} + gl_Position = vec4(vPosition * vec2(uScale) + vec2(uOffset), 0, 1); +})"; -const char *SimpleDrawVertexShaderSource() +constexpr char kSimpleDrawVS[] = R"(attribute vec2 vPosition; +const float scale = 0.5; +const float offset = -0.5; + +void main() { - return - R"(attribute vec2 vPosition; - const float scale = 0.5; - const float offset = -0.5; + gl_Position = vec4(vPosition * vec2(scale) + vec2(offset), 0, 1); +})"; - void main() - { - gl_Position = vec4(vPosition * vec2(scale) + vec2(offset), 0, 1); - })"; -} - -const char *SimpleTexCoordVertexShaderSource() -{ - return R"(attribute vec2 vPosition; +constexpr char kSimpleTexCoordVS[] = R"(attribute vec2 vPosition; varying vec2 texCoord; void main() { gl_Position = vec4(vPosition, 0, 1); texCoord = vPosition * 0.5 + vec2(0.5); })"; -} -const char *SimpleFragmentShaderSource() +constexpr char kSimpleFS[] = R"(precision mediump float; +void main() { - return - R"(precision mediump float; - void main() - { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - })"; -} + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); +})"; -const char *SimpleTextureFragmentShaderSource() -{ - return R"(precision mediump float; +constexpr char kSimpleTextureFS[] = R"(precision mediump float; varying vec2 texCoord; uniform sampler2D tex; void main() { gl_FragColor = texture2D(tex, texCoord); })"; -} void Generate2DTriangleData(size_t numTris, std::vector *floatData) { @@ -92,9 +73,7 @@ void Generate2DTriangleData(size_t numTris, std::vector *floatData) GLuint SetupSimpleScaleAndOffsetProgram() { - const std::string vs = SimpleScaleAndOffsetVertexShaderSource(); - const std::string fs = SimpleFragmentShaderSource(); - GLuint program = CompileProgram(vs, fs); + GLuint program = CompileProgram(kSimpleScaleAndOffsetVS, kSimpleFS); if (program == 0u) { return program; @@ -113,9 +92,7 @@ GLuint SetupSimpleScaleAndOffsetProgram() GLuint SetupSimpleDrawProgram() { - const std::string vs = SimpleDrawVertexShaderSource(); - const std::string fs = SimpleFragmentShaderSource(); - GLuint program = CompileProgram(vs, fs); + GLuint program = CompileProgram(kSimpleDrawVS, kSimpleFS); if (program == 0u) { return program; @@ -129,9 +106,7 @@ GLuint SetupSimpleDrawProgram() GLuint SetupSimpleTextureProgram() { - const std::string vs = SimpleTexCoordVertexShaderSource(); - const std::string fs = SimpleTextureFragmentShaderSource(); - GLuint program = CompileProgram(vs, fs); + GLuint program = CompileProgram(kSimpleTexCoordVS, kSimpleTextureFS); if (program == 0u) { return program; diff --git a/src/tests/test_utils/gl_raii.h b/src/tests/test_utils/gl_raii.h index aaed0e675..afddcfb10 100644 --- a/src/tests/test_utils/gl_raii.h +++ b/src/tests/test_utils/gl_raii.h @@ -103,25 +103,22 @@ class GLProgram void makeEmpty() { mHandle = glCreateProgram(); } - void makeCompute(const std::string &computeShader) - { - mHandle = CompileComputeProgram(computeShader); - } + void makeCompute(const char *computeShader) { mHandle = CompileComputeProgram(computeShader); } - void makeRaster(const std::string &vertexShader, const std::string &fragmentShader) + void makeRaster(const char *vertexShader, const char *fragmentShader) { mHandle = CompileProgram(vertexShader, fragmentShader); } - void makeRaster(const std::string &vertexShader, - const std::string &geometryShader, - const std::string &fragmentShader) + void makeRaster(const char *vertexShader, + const char *geometryShader, + const char *fragmentShader) { mHandle = CompileProgramWithGS(vertexShader, geometryShader, fragmentShader); } - void makeRasterWithTransformFeedback(const std::string &vertexShader, - const std::string &fragmentShader, + void makeRasterWithTransformFeedback(const char *vertexShader, + const char *fragmentShader, const std::vector &tfVaryings, GLenum bufferMode) { diff --git a/util/EGLWindow.cpp b/util/EGLWindow.cpp index a3dc25c9b..8d150f5ca 100644 --- a/util/EGLWindow.cpp +++ b/util/EGLWindow.cpp @@ -20,8 +20,7 @@ EGLPlatformParameters::EGLPlatformParameters() minorVersion(EGL_DONT_CARE), deviceType(EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE), presentPath(EGL_DONT_CARE) -{ -} +{} EGLPlatformParameters::EGLPlatformParameters(EGLint renderer) : renderer(renderer), @@ -29,8 +28,7 @@ EGLPlatformParameters::EGLPlatformParameters(EGLint renderer) minorVersion(EGL_DONT_CARE), deviceType(EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE), presentPath(EGL_DONT_CARE) -{ -} +{} EGLPlatformParameters::EGLPlatformParameters(EGLint renderer, EGLint majorVersion, @@ -41,8 +39,7 @@ EGLPlatformParameters::EGLPlatformParameters(EGLint renderer, minorVersion(minorVersion), deviceType(deviceType), presentPath(EGL_DONT_CARE) -{ -} +{} EGLPlatformParameters::EGLPlatformParameters(EGLint renderer, EGLint majorVersion, @@ -54,8 +51,7 @@ EGLPlatformParameters::EGLPlatformParameters(EGLint renderer, minorVersion(minorVersion), deviceType(deviceType), presentPath(presentPath) -{ -} +{} bool operator<(const EGLPlatformParameters &a, const EGLPlatformParameters &b) { @@ -122,8 +118,7 @@ EGLWindow::EGLWindow(EGLint glesMajorVersion, mContextProgramCacheEnabled(), mContextVirtualization(), mPlatformMethods(nullptr) -{ -} +{} EGLWindow::~EGLWindow() { @@ -290,7 +285,8 @@ bool EGLWindow::initializeDisplayAndSurface(OSWindow *osWindow) surfaceAttributes.push_back(EGL_NONE); - mSurface = eglCreateWindowSurface(mDisplay, mConfig, osWindow->getNativeWindow(), &surfaceAttributes[0]); + mSurface = eglCreateWindowSurface(mDisplay, mConfig, osWindow->getNativeWindow(), + &surfaceAttributes[0]); if (eglGetError() != EGL_SUCCESS) { destroyGL(); @@ -484,9 +480,7 @@ void EGLWindow::destroyGL() bool EGLWindow::isGLInitialized() const { - return mSurface != EGL_NO_SURFACE && - mContext != EGL_NO_CONTEXT && - mDisplay != EGL_NO_DISPLAY; + return mSurface != EGL_NO_SURFACE && mContext != EGL_NO_CONTEXT && mDisplay != EGL_NO_DISPLAY; } // Find an EGLConfig that is an exact match for the specified attributes. EGL_FALSE is returned if diff --git a/util/EGLWindow.h b/util/EGLWindow.h index c4c251f92..1977ffc64 100644 --- a/util/EGLWindow.h +++ b/util/EGLWindow.h @@ -7,20 +7,20 @@ #ifndef UTIL_EGLWINDOW_H_ #define UTIL_EGLWINDOW_H_ +#include #include #include -#include #include -#include +#include +#include #include #include #include -#include -#include +#include -#include "common/angleutils.h" #include "common/Optional.h" +#include "common/angleutils.h" class OSWindow; @@ -39,7 +39,10 @@ struct ANGLE_EXPORT EGLPlatformParameters EGLPlatformParameters(); explicit EGLPlatformParameters(EGLint renderer); - EGLPlatformParameters(EGLint renderer, EGLint majorVersion, EGLint minorVersion, EGLint deviceType); + EGLPlatformParameters(EGLint renderer, + EGLint majorVersion, + EGLint minorVersion, + EGLint deviceType); EGLPlatformParameters(EGLint renderer, EGLint majorVersion, EGLint minorVersion, @@ -169,4 +172,4 @@ class ANGLE_EXPORT EGLWindow : angle::NonCopyable ANGLE_EXPORT bool CheckExtensionExists(const char *allExtensions, const std::string &extName); -#endif // UTIL_EGLWINDOW_H_ +#endif // UTIL_EGLWINDOW_H_ diff --git a/util/shader_utils.cpp b/util/shader_utils.cpp index da41517b6..97fa9f30e 100644 --- a/util/shader_utils.cpp +++ b/util/shader_utils.cpp @@ -6,11 +6,14 @@ #include "shader_utils.h" +#include #include #include #include -static std::string ReadFileToString(const std::string &source) +namespace +{ +std::string ReadFileToString(const std::string &source) { std::ifstream stream(source.c_str()); if (!stream) @@ -30,11 +33,62 @@ static std::string ReadFileToString(const std::string &source) return result; } -GLuint CompileShader(GLenum type, const std::string &source) +GLuint CompileProgramInternal(const char *vsSource, + const char *gsSource, + const char *fsSource, + const std::function &preLinkCallback) +{ + GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); + GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); + + if (vs == 0 || fs == 0) + { + glDeleteShader(fs); + glDeleteShader(vs); + return 0; + } + + GLuint program = glCreateProgram(); + + glAttachShader(program, vs); + glDeleteShader(vs); + + glAttachShader(program, fs); + glDeleteShader(fs); + + GLuint gs = 0; + + if (strlen(gsSource) > 0) + { + gs = CompileShader(GL_GEOMETRY_SHADER_EXT, gsSource); + if (gs == 0) + { + glDeleteShader(vs); + glDeleteShader(fs); + glDeleteProgram(program); + return 0; + } + + glAttachShader(program, gs); + glDeleteShader(gs); + } + + if (preLinkCallback) + { + preLinkCallback(program); + } + + glLinkProgram(program); + + return CheckLinkStatusAndReturnProgram(program, true); +} +} // namespace + +GLuint CompileShader(GLenum type, const char *source) { GLuint shader = glCreateShader(type); - const char *sourceArray[1] = {source.c_str()}; + const char *sourceArray[1] = {source}; glShaderSource(shader, 1, sourceArray, nullptr); glCompileShader(shader); @@ -76,7 +130,7 @@ GLuint CompileShaderFromFile(GLenum type, const std::string &sourcePath) return 0; } - return CompileShader(type, source); + return CompileShader(type, source.c_str()); } GLuint CheckLinkStatusAndReturnProgram(GLuint program, bool outputErrorMessages) @@ -116,59 +170,9 @@ GLuint CheckLinkStatusAndReturnProgram(GLuint program, bool outputErrorMessages) return program; } -static GLuint CompileProgramInternal(const std::string &vsSource, - const std::string &gsSource, - const std::string &fsSource, - const std::function &preLinkCallback) -{ - GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource); - GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource); - - if (vs == 0 || fs == 0) - { - glDeleteShader(fs); - glDeleteShader(vs); - return 0; - } - - GLuint program = glCreateProgram(); - - glAttachShader(program, vs); - glDeleteShader(vs); - - glAttachShader(program, fs); - glDeleteShader(fs); - - GLuint gs = 0; - - if (!gsSource.empty()) - { - gs = CompileShader(GL_GEOMETRY_SHADER_EXT, gsSource); - if (gs == 0) - { - glDeleteShader(vs); - glDeleteShader(fs); - glDeleteProgram(program); - return 0; - } - - glAttachShader(program, gs); - glDeleteShader(gs); - } - - if (preLinkCallback) - { - preLinkCallback(program); - } - - glLinkProgram(program); - - return CheckLinkStatusAndReturnProgram(program, true); -} - GLuint CompileProgramWithTransformFeedback( - const std::string &vsSource, - const std::string &fsSource, + const char *vsSource, + const char *fsSource, const std::vector &transformFeedbackVaryings, GLenum bufferMode) { @@ -191,21 +195,19 @@ GLuint CompileProgramWithTransformFeedback( return CompileProgramInternal(vsSource, "", fsSource, preLink); } -GLuint CompileProgram(const std::string &vsSource, const std::string &fsSource) +GLuint CompileProgram(const char *vsSource, const char *fsSource) { return CompileProgramInternal(vsSource, "", fsSource, nullptr); } -GLuint CompileProgram(const std::string &vsSource, - const std::string &fsSource, +GLuint CompileProgram(const char *vsSource, + const char *fsSource, const std::function &preLinkCallback) { return CompileProgramInternal(vsSource, "", fsSource, preLinkCallback); } -GLuint CompileProgramWithGS(const std::string &vsSource, - const std::string &gsSource, - const std::string &fsSource) +GLuint CompileProgramWithGS(const char *vsSource, const char *gsSource, const char *fsSource) { return CompileProgramInternal(vsSource, gsSource, fsSource, nullptr); } @@ -219,10 +221,10 @@ GLuint CompileProgramFromFiles(const std::string &vsPath, const std::string &fsP return 0; } - return CompileProgram(vsSource, fsSource); + return CompileProgram(vsSource.c_str(), fsSource.c_str()); } -GLuint CompileComputeProgram(const std::string &csSource, bool outputErrorMessages) +GLuint CompileComputeProgram(const char *csSource, bool outputErrorMessages) { GLuint program = glCreateProgram(); diff --git a/util/shader_utils.h b/util/shader_utils.h index b401f4455..08107baeb 100644 --- a/util/shader_utils.h +++ b/util/shader_utils.h @@ -19,28 +19,29 @@ #include #include +struct ShaderFuncs; + ANGLE_EXPORT GLuint CheckLinkStatusAndReturnProgram(GLuint program, bool outputErrorMessages); -ANGLE_EXPORT GLuint CompileShader(GLenum type, const std::string &source); +ANGLE_EXPORT GLuint CompileShader(GLenum type, const char *source); ANGLE_EXPORT GLuint CompileShaderFromFile(GLenum type, const std::string &sourcePath); ANGLE_EXPORT GLuint -CompileProgramWithTransformFeedback(const std::string &vsSource, - const std::string &fsSource, +CompileProgramWithTransformFeedback(const char *vsSource, + const char *fsSource, const std::vector &transformFeedbackVaryings, GLenum bufferMode); -ANGLE_EXPORT GLuint CompileProgram(const std::string &vsSource, const std::string &fsSource); +ANGLE_EXPORT GLuint CompileProgram(const char *vsSource, const char *fsSource); -ANGLE_EXPORT GLuint CompileProgram(const std::string &vsSource, - const std::string &fsSource, +ANGLE_EXPORT GLuint CompileProgram(const char *vsSource, + const char *fsSource, const std::function &preLinkCallback); -ANGLE_EXPORT GLuint CompileProgramWithGS(const std::string &vsSource, - const std::string &gsSource, - const std::string &fsSource); +ANGLE_EXPORT GLuint CompileProgramWithGS(const char *vsSource, + const char *gsSource, + const char *fsSource); ANGLE_EXPORT GLuint CompileProgramFromFiles(const std::string &vsPath, const std::string &fsPath); -ANGLE_EXPORT GLuint CompileComputeProgram(const std::string &csSource, - bool outputErrorMessages = true); +ANGLE_EXPORT GLuint CompileComputeProgram(const char *csSource, bool outputErrorMessages = true); ANGLE_EXPORT bool LinkAttachedProgram(GLuint program); ANGLE_EXPORT GLuint LoadBinaryProgramOES(const std::vector &binary, GLenum binaryFormat);