1 2typedef struct FragmentTestRec { 3 const char * name; 4 uint32_t texCount; 5 const char * txt; 6} FragmentTest; 7 8static FragmentTest fpFill = { 9 "Solid color", 0, 10 11 "precision mediump float;\n" 12 "uniform vec4 u_color;\n" 13 "void main() {\n" 14 " gl_FragColor = u_color;\n" 15 "}\n" 16}; 17 18static FragmentTest fpGradient = { 19 "Solid gradient", 0, 20 21 "precision mediump float;\n" 22 "varying lowp vec4 v_color;\n" 23 "void main() {\n" 24 " gl_FragColor = v_color;\n" 25 "}\n" 26}; 27 28static FragmentTest fpCopyTex = { 29 "Texture copy", 1, 30 31 "precision mediump float;\n" 32 "varying vec2 v_tex0;\n" 33 "uniform sampler2D u_tex0;\n" 34 "void main() {\n" 35 " gl_FragColor = texture2D(u_tex0, v_tex0);\n" 36 "}\n" 37}; 38 39static FragmentTest fpCopyTexGamma = { 40 "Texture copy with gamma", 1, 41 42 "precision mediump float;\n" 43 "varying vec2 v_tex0;\n" 44 "uniform sampler2D u_tex0;\n" 45 "void main() {\n" 46 " vec4 t = texture2D(u_tex0, v_tex0);\n" 47 " t.rgb = pow(t.rgb, vec3(1.4, 1.4, 1.4));\n" 48 " gl_FragColor = t;\n" 49 "}\n" 50}; 51 52static FragmentTest fpTexSpec = { 53 "Texture spec", 1, 54 55 "precision mediump float;\n" 56 "varying vec2 v_tex0;\n" 57 "uniform sampler2D u_tex0;\n" 58 "void main() {\n" 59 " vec4 t = texture2D(u_tex0, v_tex0);\n" 60 " float simSpec = dot(gl_FragCoord.xyz, gl_FragCoord.xyz);\n" 61 " simSpec = pow(clamp(simSpec, 0.1, 1.0), 40.0);\n" 62 " gl_FragColor = t + vec4(simSpec, simSpec, simSpec, simSpec);\n" 63 "}\n" 64}; 65 66static FragmentTest fpDepTex = { 67 "Dependent Lookup", 1, 68 69 "precision mediump float;\n" 70 "varying vec2 v_tex0;\n" 71 "uniform sampler2D u_tex0;\n" 72 "void main() {\n" 73 " vec4 t = texture2D(u_tex0, v_tex0);\n" 74 " t += texture2D(u_tex0, t.xy);\n" 75 " gl_FragColor = t;\n" 76 "}\n" 77}; 78 79static FragmentTest fpModulateConstantTex = { 80 "Texture modulate constant", 1, 81 82 "precision mediump float;\n" 83 "varying vec2 v_tex0;\n" 84 "uniform sampler2D u_tex0;\n" 85 "uniform vec4 u_color;\n" 86 87 "void main() {\n" 88 " lowp vec4 c = texture2D(u_tex0, v_tex0);\n" 89 " c *= u_color;\n" 90 " gl_FragColor = c;\n" 91 "}\n" 92}; 93 94static FragmentTest fpModulateVaryingTex = { 95 "Texture modulate gradient", 1, 96 97 "precision mediump float;\n" 98 "varying vec2 v_tex0;\n" 99 "varying lowp vec4 v_color;\n" 100 "uniform sampler2D u_tex0;\n" 101 102 "void main() {\n" 103 " lowp vec4 c = texture2D(u_tex0, v_tex0);\n" 104 " c *= v_color;\n" 105 " gl_FragColor = c;\n" 106 "}\n" 107}; 108 109static FragmentTest fpModulateVaryingConstantTex = { 110 "Texture modulate gradient constant", 1, 111 112 "precision mediump float;\n" 113 "varying vec2 v_tex0;\n" 114 "varying lowp vec4 v_color;\n" 115 "uniform sampler2D u_tex0;\n" 116 "uniform vec4 u_color;\n" 117 118 "void main() {\n" 119 " lowp vec4 c = texture2D(u_tex0, v_tex0);\n" 120 " c *= v_color;\n" 121 " c *= u_color;\n" 122 " gl_FragColor = c;\n" 123 "}\n" 124}; 125 126static FragmentTest *gFragmentTests[] = { 127 &fpFill, 128 &fpGradient, 129 &fpCopyTex, 130 &fpCopyTexGamma, 131 &fpTexSpec, 132 &fpDepTex, 133 &fpModulateConstantTex, 134 &fpModulateVaryingTex, 135 &fpModulateVaryingConstantTex, 136 137}; 138 139static const size_t gFragmentTestCount = sizeof(gFragmentTests) / sizeof(gFragmentTests[0]); 140