Hash :
a20af6d7
Author :
Date :
2017-09-18T13:32:29
Use C++11 raw string literals instead of SHADER_SOURCE macro This is better in many ways: 1. It doesn't confuse clang format 2. \n doesn't need to be included after preprocessor directives like the version directive. 3. It's using built-in functionality instead of something custom. Raw string literals should be the preferred way to include shader source in C++ files going forward. BUG=angleproject:2157 TEST=angle_end2end_tests Change-Id: I8b236a6e2d5c25d920297e5bc5b5b143eddeba1f Reviewed-on: https://chromium-review.googlesource.com/671046 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "test_utils/ANGLETest.h"
using namespace angle;
class BlendMinMaxTest : public ANGLETest
{
protected:
BlendMinMaxTest()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
mProgram = 0;
mColorLocation = -1;
mFramebuffer = 0;
mColorRenderbuffer = 0;
}
struct Color
{
float values[4];
};
static float getExpected(bool blendMin, float curColor, float prevColor)
{
return blendMin ? std::min(curColor, prevColor) : std::max(curColor, prevColor);
}
void runTest(GLenum colorFormat, GLenum type)
{
if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_blend_minmax"))
{
std::cout << "Test skipped because ES3 or GL_EXT_blend_minmax is not available." << std::endl;
return;
}
// TODO(geofflang): figure out why this fails
if (IsIntel() && GetParam() == ES2_OPENGL())
{
std::cout << "Test skipped on OpenGL Intel due to flakyness." << std::endl;
return;
}
SetUpFramebuffer(colorFormat);
int minValue = 0;
int maxValue = 1;
if (type == GL_FLOAT)
{
minValue = -1024;
maxValue = 1024;
}
const size_t colorCount = 128;
Color colors[colorCount];
for (size_t i = 0; i < colorCount; i++)
{
for (size_t j = 0; j < 4; j++)
{
colors[i].values[j] =
static_cast<float>(minValue + (rand() % (maxValue - minValue)));
}
}
float prevColor[4];
for (size_t i = 0; i < colorCount; i++)
{
const Color &color = colors[i];
glUseProgram(mProgram);
glUniform4f(mColorLocation, color.values[0], color.values[1], color.values[2], color.values[3]);
bool blendMin = (rand() % 2 == 0);
glBlendEquation(blendMin ? GL_MIN : GL_MAX);
drawQuad(mProgram, "aPosition", 0.5f);
float pixel[4];
if (type == GL_UNSIGNED_BYTE)
{
GLubyte ubytePixel[4];
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, ubytePixel);
for (size_t componentIdx = 0; componentIdx < ArraySize(pixel); componentIdx++)
{
pixel[componentIdx] = ubytePixel[componentIdx] / 255.0f;
}
}
else if (type == GL_FLOAT)
{
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, pixel);
}
else
{
FAIL() << "Unexpected pixel type";
}
if (i > 0)
{
const float errorRange = 1.0f / 255.0f;
for (size_t componentIdx = 0; componentIdx < ArraySize(pixel); componentIdx++)
{
EXPECT_NEAR(
getExpected(blendMin, color.values[componentIdx], prevColor[componentIdx]),
pixel[componentIdx], errorRange);
}
}
memcpy(prevColor, pixel, sizeof(pixel));
}
}
virtual void SetUp()
{
ANGLETest::SetUp();
const std::string testVertexShaderSource =
R"(attribute highp vec4 aPosition;
void main(void)
{
gl_Position = aPosition;
})";
const std::string testFragmentShaderSource =
R"(uniform highp vec4 color;
void main(void)
{
gl_FragColor = color;
})";
mProgram = CompileProgram(testVertexShaderSource, testFragmentShaderSource);
if (mProgram == 0)
{
FAIL() << "shader compilation failed.";
}
mColorLocation = glGetUniformLocation(mProgram, "color");
glUseProgram(mProgram);
glClearColor(0, 0, 0, 0);
glClearDepthf(0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
}
void SetUpFramebuffer(GLenum colorFormat)
{
glGenFramebuffers(1, &mFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mFramebuffer);
glBindFramebuffer(GL_READ_FRAMEBUFFER, mFramebuffer);
glGenRenderbuffers(1, &mColorRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, mColorRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, colorFormat, getWindowWidth(), getWindowHeight());
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, mColorRenderbuffer);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
ASSERT_GL_NO_ERROR();
}
virtual void TearDown()
{
glDeleteProgram(mProgram);
glDeleteFramebuffers(1, &mFramebuffer);
glDeleteRenderbuffers(1, &mColorRenderbuffer);
ANGLETest::TearDown();
}
GLuint mProgram;
GLint mColorLocation;
GLuint mFramebuffer;
GLuint mColorRenderbuffer;
};
TEST_P(BlendMinMaxTest, RGBA8)
{
runTest(GL_RGBA8, GL_UNSIGNED_BYTE);
}
TEST_P(BlendMinMaxTest, RGBA32F)
{
if (getClientMajorVersion() < 3 || !extensionEnabled("GL_EXT_color_buffer_float"))
{
std::cout << "Test skipped because ES3 and GL_EXT_color_buffer_float are not available."
<< std::endl;
return;
}
// TODO(jmadill): Figure out why this is broken on Intel
if (IsIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9()))
{
std::cout << "Test skipped on Intel OpenGL." << std::endl;
return;
}
// TODO (bug 1284): Investigate RGBA32f D3D SDK Layers messages on D3D11_FL9_3
if (IsD3D11_FL93())
{
std::cout << "Test skipped on Feature Level 9_3." << std::endl;
return;
}
runTest(GL_RGBA32F, GL_FLOAT);
}
TEST_P(BlendMinMaxTest, RGBA16F)
{
if (getClientMajorVersion() < 3 && !extensionEnabled("GL_EXT_color_buffer_half_float"))
{
std::cout << "Test skipped because ES3 or GL_EXT_color_buffer_half_float is not available."
<< std::endl;
return;
}
// TODO(jmadill): figure out why this fails
if (IsIntel() && (GetParam() == ES2_D3D11() || GetParam() == ES2_D3D9()))
{
std::cout << "Test skipped on Intel due to failures." << std::endl;
return;
}
runTest(GL_RGBA16F, GL_FLOAT);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(BlendMinMaxTest,
ES2_D3D9(),
ES2_D3D11(),
ES3_D3D11(),
ES2_D3D11_FL9_3(),
ES2_OPENGL(),
ES3_OPENGL(),
ES2_OPENGLES(),
ES3_OPENGLES());