OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "main.h" |
| 6 #include "testbase.h" |
| 7 #include "utils.h" |
| 8 |
| 9 |
| 10 namespace glbench { |
| 11 |
| 12 |
| 13 class VaryingsAndDdxyShaderTest : public DrawElementsTestFunc { |
| 14 public: |
| 15 VaryingsAndDdxyShaderTest() {} |
| 16 virtual ~VaryingsAndDdxyShaderTest() {} |
| 17 virtual bool Run(); |
| 18 |
| 19 private: |
| 20 DISALLOW_COPY_AND_ASSIGN(VaryingsAndDdxyShaderTest); |
| 21 }; |
| 22 |
| 23 #if I915_WORKAROUND |
| 24 #define V1 "gl_TexCoord[0]" |
| 25 #define V2 "gl_TexCoord[1]" |
| 26 #define V3 "gl_TexCoord[2]" |
| 27 #define V4 "gl_TexCoord[3]" |
| 28 #define V5 "gl_TexCoord[4]" |
| 29 #define V6 "gl_TexCoord[5]" |
| 30 #define V7 "gl_TexCoord[6]" |
| 31 #define V8 "gl_TexCoord[7]" |
| 32 #define DDX "dFdx" |
| 33 #define DDY "dFdy" |
| 34 #else |
| 35 #define V1 "v1" |
| 36 #define V2 "v2" |
| 37 #define V3 "v3" |
| 38 #define V4 "v4" |
| 39 #define V5 "v5" |
| 40 #define V6 "v6" |
| 41 #define V7 "v7" |
| 42 #define V8 "v8" |
| 43 #define DDX "ddx" |
| 44 #define DDY "ddy" |
| 45 #endif |
| 46 |
| 47 |
| 48 const char *vertex_shader_1_varying = |
| 49 "attribute vec4 c;" |
| 50 "varying vec4 v1;" |
| 51 "void main() {" |
| 52 " gl_Position = c;" |
| 53 V1 "= c;" |
| 54 "}"; |
| 55 |
| 56 const char *vertex_shader_2_varying = |
| 57 "attribute vec4 c;" |
| 58 "varying vec4 v1;" |
| 59 "varying vec4 v2;" |
| 60 "void main() {" |
| 61 " gl_Position = c;" |
| 62 V1 "=" V2 "= c/2.;" |
| 63 "}"; |
| 64 |
| 65 const char *vertex_shader_4_varying = |
| 66 "attribute vec4 c;" |
| 67 "varying vec4 v1;" |
| 68 "varying vec4 v2;" |
| 69 "varying vec4 v3;" |
| 70 "varying vec4 v4;" |
| 71 "void main() {" |
| 72 " gl_Position = c;" |
| 73 V1 "=" V2 "=" V3 "=" V4 "= c/4.;" |
| 74 "}"; |
| 75 |
| 76 const char *vertex_shader_8_varying = |
| 77 "attribute vec4 c;" |
| 78 "varying vec4 v1;" |
| 79 "varying vec4 v2;" |
| 80 "varying vec4 v3;" |
| 81 "varying vec4 v4;" |
| 82 "varying vec4 v5;" |
| 83 "varying vec4 v6;" |
| 84 "varying vec4 v7;" |
| 85 "varying vec4 v8;" |
| 86 "void main() {" |
| 87 " gl_Position = c;" |
| 88 V1 "=" V2 "=" V3 "=" V4 "=" V5 "=" V6 "=" V7 "=" V8 "= c/8.;" |
| 89 "}"; |
| 90 |
| 91 const char *fragment_shader_1_varying = |
| 92 "varying vec4 v1;" |
| 93 "void main() {" |
| 94 " gl_FragColor =" V1 ";" |
| 95 "}"; |
| 96 |
| 97 const char *fragment_shader_2_varying = |
| 98 "varying vec4 v1;" |
| 99 "varying vec4 v2;" |
| 100 "void main() {" |
| 101 " gl_FragColor =" V1 "+" V2 ";" |
| 102 "}"; |
| 103 |
| 104 const char *fragment_shader_4_varying = |
| 105 "varying vec4 v1;" |
| 106 "varying vec4 v2;" |
| 107 "varying vec4 v3;" |
| 108 "varying vec4 v4;" |
| 109 "void main() {" |
| 110 " gl_FragColor =" V1 "+" V2 "+" V3 "+" V4 ";" |
| 111 "}"; |
| 112 |
| 113 const char *fragment_shader_8_varying = |
| 114 "varying vec4 v1;" |
| 115 "varying vec4 v2;" |
| 116 "varying vec4 v3;" |
| 117 "varying vec4 v4;" |
| 118 "varying vec4 v5;" |
| 119 "varying vec4 v6;" |
| 120 "varying vec4 v7;" |
| 121 "varying vec4 v8;" |
| 122 "void main() {" |
| 123 " gl_FragColor =" V1 "+" V2 "+" V3 "+" V4 "+" V5 "+" V6 "+" V7 "+" V8 ";" |
| 124 "}"; |
| 125 |
| 126 GLuint VaryingsShaderProgram(int varyings_count, GLuint vertex_buffer) { |
| 127 const char *vertex_shader = NULL; |
| 128 const char *fragment_shader = NULL; |
| 129 switch (varyings_count) { |
| 130 case 1: |
| 131 vertex_shader = vertex_shader_1_varying; |
| 132 fragment_shader = fragment_shader_1_varying; |
| 133 break; |
| 134 case 2: |
| 135 vertex_shader = vertex_shader_2_varying; |
| 136 fragment_shader = fragment_shader_2_varying; |
| 137 break; |
| 138 case 4: |
| 139 vertex_shader = vertex_shader_4_varying; |
| 140 fragment_shader = fragment_shader_4_varying; |
| 141 break; |
| 142 case 8: |
| 143 vertex_shader = vertex_shader_8_varying; |
| 144 fragment_shader = fragment_shader_8_varying; |
| 145 break; |
| 146 default: return 0; |
| 147 } |
| 148 GLuint program = |
| 149 InitShaderProgram(vertex_shader, fragment_shader); |
| 150 |
| 151 int attribute_index = glGetAttribLocation(program, "c"); |
| 152 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); |
| 153 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL); |
| 154 glEnableVertexAttribArray(attribute_index); |
| 155 |
| 156 return program; |
| 157 } |
| 158 |
| 159 |
| 160 const char *fragment_shader_ddx = |
| 161 "varying vec4 v1;" |
| 162 "void main() {" |
| 163 " gl_FragColor = vec4(" DDX "(" V1 ".x), 0., 0., 1.);" |
| 164 "}"; |
| 165 |
| 166 const char *fragment_shader_ddy = |
| 167 "varying vec4 v1;" |
| 168 "void main() {" |
| 169 " gl_FragColor = vec4(" DDY "(" V1 ".y), 0., 0., 1.);" |
| 170 "}"; |
| 171 |
| 172 GLuint DdxDdyShaderProgram(bool ddx, GLuint vertex_buffer) { |
| 173 GLuint program = |
| 174 InitShaderProgram(vertex_shader_1_varying, |
| 175 ddx ? fragment_shader_ddx : fragment_shader_ddy); |
| 176 |
| 177 int attribute_index = glGetAttribLocation(program, "c"); |
| 178 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); |
| 179 glVertexAttribPointer(attribute_index, 2, GL_FLOAT, GL_FALSE, 0, NULL); |
| 180 glEnableVertexAttribArray(attribute_index); |
| 181 |
| 182 return program; |
| 183 } |
| 184 |
| 185 |
| 186 bool VaryingsAndDdxyShaderTest::Run() { |
| 187 glViewport(-g_width, -g_height, g_width*2, g_height*2); |
| 188 |
| 189 const int c = 4; |
| 190 GLfloat *vertices = NULL; |
| 191 GLsizeiptr vertex_buffer_size = 0; |
| 192 CreateLattice(&vertices, &vertex_buffer_size, 1.f / c, 1.f / c, c, c); |
| 193 GLuint vertex_buffer = SetupVBO(GL_ARRAY_BUFFER, |
| 194 vertex_buffer_size, vertices); |
| 195 |
| 196 GLuint *indices = NULL; |
| 197 GLuint index_buffer = 0; |
| 198 GLsizeiptr index_buffer_size = 0; |
| 199 |
| 200 count_ = CreateMesh(&indices, &index_buffer_size, c, c, 0); |
| 201 index_buffer = SetupVBO(GL_ELEMENT_ARRAY_BUFFER, |
| 202 index_buffer_size, indices); |
| 203 |
| 204 GLuint program = VaryingsShaderProgram(1, vertex_buffer); |
| 205 RunTest(this, |
| 206 "mpixels_sec_varyings_shader_1", g_width * g_height, true); |
| 207 glDeleteProgram(program); |
| 208 |
| 209 program = VaryingsShaderProgram(2, vertex_buffer); |
| 210 RunTest(this, |
| 211 "mpixels_sec_varyings_shader_2", g_width * g_height, true); |
| 212 glDeleteProgram(program); |
| 213 |
| 214 program = VaryingsShaderProgram(4, vertex_buffer); |
| 215 RunTest(this, |
| 216 "mpixels_sec_varyings_shader_4", g_width * g_height, true); |
| 217 glDeleteProgram(program); |
| 218 |
| 219 program = VaryingsShaderProgram(8, vertex_buffer); |
| 220 RunTest(this, |
| 221 "mpixels_sec_varyings_shader_8", g_width * g_height, true); |
| 222 glDeleteProgram(program); |
| 223 |
| 224 program = DdxDdyShaderProgram(true, vertex_buffer); |
| 225 RunTest(this, |
| 226 "mpixels_sec_ddx_shader", g_width * g_height, true); |
| 227 glDeleteProgram(program); |
| 228 |
| 229 program = DdxDdyShaderProgram(false, vertex_buffer); |
| 230 RunTest(this, |
| 231 "mpixels_sec_ddy_shader", g_width * g_height, true); |
| 232 glDeleteProgram(program); |
| 233 |
| 234 glDeleteBuffers(1, &index_buffer); |
| 235 delete[] indices; |
| 236 |
| 237 glDeleteBuffers(1, &vertex_buffer); |
| 238 delete[] vertices; |
| 239 |
| 240 return true; |
| 241 } |
| 242 |
| 243 |
| 244 TestBase* GetVaryingsAndDdxyShaderTest() { |
| 245 return new VaryingsAndDdxyShaderTest; |
| 246 } |
| 247 |
| 248 |
| 249 } // namespace glbench |
OLD | NEW |