Moved selection of I915 hack out of the YUV shader.
Review URL: http://codereview.chromium.org/2152003
diff --git a/client/deps/glbench/src/utils.cc b/client/deps/glbench/src/utils.cc
index 4d2aca4..8709faf 100644
--- a/client/deps/glbench/src/utils.cc
+++ b/client/deps/glbench/src/utils.cc
@@ -165,11 +165,23 @@
}
GLuint InitShaderProgram(const char *vertex_src, const char *fragment_src) {
+ return InitShaderProgramWithHeader(NULL, vertex_src, fragment_src);
+}
+
+GLuint InitShaderProgramWithHeader(const char* header,
+ const char* vertex_src,
+ const char* fragment_src) {
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(vertex_shader, 1, &vertex_src, NULL);
- glShaderSource(fragment_shader, 1, &fragment_src, NULL);
+ const char* header_and_body[2];
+ header_and_body[0] = header ? header : "";
+ header_and_body[1] = vertex_src;
+ glShaderSource(vertex_shader,
+ arraysize(header_and_body), header_and_body, NULL);
+ header_and_body[1] = fragment_src;
+ glShaderSource(fragment_shader,
+ arraysize(header_and_body), header_and_body, NULL);
glCompileShader(vertex_shader);
print_info_log(vertex_shader);
diff --git a/client/deps/glbench/src/utils.h b/client/deps/glbench/src/utils.h
index 20fce92..434d081 100644
--- a/client/deps/glbench/src/utils.h
+++ b/client/deps/glbench/src/utils.h
@@ -24,6 +24,9 @@
int CreateMesh(GLuint **indices, GLsizeiptr *size,
int width, int height, int culled_ratio);
GLuint InitShaderProgram(const char *vertex_src, const char *fragment_src);
+GLuint InitShaderProgramWithHeader(const char* header,
+ const char* vertex_src,
+ const char* fragment_src);
} // namespace glbench
diff --git a/client/deps/glbench/src/yuv2rgb_1.glslf b/client/deps/glbench/src/yuv2rgb_1.glslf
index c30ef26..228e6a9 100644
--- a/client/deps/glbench/src/yuv2rgb_1.glslf
+++ b/client/deps/glbench/src/yuv2rgb_1.glslf
@@ -33,7 +33,6 @@
* This is a conversion of a cg shader from Chrome:
* http://src.chromium.org/viewvc/chrome/trunk/src/o3d/samples/shaders/yuv2rgb.shader
*/
-#define I915_WORKAROUND 1
/*
* This shader takes a Y'UV420p image as a single greyscale plane, and
@@ -178,7 +177,7 @@
* the location in the image stream, using floor in several places
* which makes it hard to use parametric coordinates.
*/
-#if I915_WORKAROUND
+#if defined(I915_WORKAROUND)
vec2 pixelPosition = vec2(floor(imageWidth * gl_TexCoord[0].x),
floor(imageHeight * gl_TexCoord[0].y));
#else
@@ -190,7 +189,7 @@
* We can use the parametric coordinates to get the Y channel, since it's
* a relatively normal image.
*/
-#if I915_WORKAROUND
+#if defined(I915_WORKAROUND)
float yChannel = getYPixel(vec2(gl_TexCoord[0]));
#else
float yChannel = getYPixel(vec2(v1));
diff --git a/client/deps/glbench/src/yuv2rgb_1.glslv b/client/deps/glbench/src/yuv2rgb_1.glslv
index bee9e8a..0f7407d 100644
--- a/client/deps/glbench/src/yuv2rgb_1.glslv
+++ b/client/deps/glbench/src/yuv2rgb_1.glslv
@@ -1,11 +1,9 @@
-#define I915_WORKAROUND 1
-
attribute vec4 c;
varying vec4 v1;
void main() {
gl_Position = c;
-#if I915_WORKAROUND
+#if defined(I915_WORKAROUND)
gl_TexCoord[0] = c;
#else
v1 = c;
diff --git a/client/deps/glbench/src/yuv2rgb_2.glslf b/client/deps/glbench/src/yuv2rgb_2.glslf
index 8f22763..81c7a17 100644
--- a/client/deps/glbench/src/yuv2rgb_2.glslf
+++ b/client/deps/glbench/src/yuv2rgb_2.glslf
@@ -35,8 +35,6 @@
* of the original image is 2 modulo 4.
*/
-#define I915_WORKAROUND 1
-
uniform sampler2D textureSampler;
uniform sampler2D paritySampler;
@@ -49,7 +47,7 @@
/*
* If the height of the original image is even, offset_odd is not needed.
*/
-#if I915_WORKAROUND
+#if defined(I915_WORKAROUND)
vec2 offset_even = vec2(texture2D(paritySampler, gl_TexCoord[0].xy).x * 0.5,
0.0);
#else
@@ -57,7 +55,7 @@
#endif
vec2 offset_odd = vec2(0.5 - offset_even.x, 0.0);
-#if I915_WORKAROUND
+#if defined(I915_WORKAROUND)
float yChannel = texture2D(textureSampler, gl_TexCoord[0].zw).x;
float uChannel = texture2D(textureSampler, gl_TexCoord[1].xy + offset_even).x;
float vChannel = texture2D(textureSampler, gl_TexCoord[1].zw + offset_odd).x;
diff --git a/client/deps/glbench/src/yuv2rgb_2.glslv b/client/deps/glbench/src/yuv2rgb_2.glslv
index 6157525..9af7eca 100644
--- a/client/deps/glbench/src/yuv2rgb_2.glslv
+++ b/client/deps/glbench/src/yuv2rgb_2.glslv
@@ -2,8 +2,6 @@
attribute vec4 c;
-#define I915_WORKAROUND 1
-
varying vec2 lineCounter;
varying vec2 yPlane;
varying vec2 uPlane;
@@ -11,7 +9,7 @@
void main() {
gl_Position = c;
-#if I915_WORKAROUND
+#if defined(I915_WORKAROUND)
gl_TexCoord[0].xy = vec2(c.y * imageHeight / 4.0, 0.0);
gl_TexCoord[0].zw = vec2(c.x, (2.0 * c.y + 1.0) / 3.0);
gl_TexCoord[1].xy = vec2(c.x / 2.0, (c.y + 1.0) / 6.0);
diff --git a/client/deps/glbench/src/yuvtest.cc b/client/deps/glbench/src/yuvtest.cc
index fb1b910..4a22079 100644
--- a/client/deps/glbench/src/yuvtest.cc
+++ b/client/deps/glbench/src/yuvtest.cc
@@ -43,7 +43,13 @@
goto done;
{
- program = InitShaderProgram(yuv_to_rgb_vertex, yuv_to_rgb_fragment);
+#if defined(I915_WORKAROUND)
+ const char* header = "#define I915_WORKAROUND 1\n";
+#else
+ const char* header = NULL;
+#endif
+ program = InitShaderProgramWithHeader(header, yuv_to_rgb_vertex,
+ yuv_to_rgb_fragment);
int imageWidthUniform = glGetUniformLocation(program, "imageWidth");
int imageHeightUniform = glGetUniformLocation(program, "imageHeight");