Home | History | Annotate | Download | only in shaders
      1 group if "If Statements"
      2 
      3 	case single_statement
      4 		version 300 es
      5 		values
      6 		{
      7 			input float in0 = [ 0.0 | 1.0 | 2.0 ];
      8 			output float out0 = [ 0.0 | 1.0 | 1.0 ];
      9 		}
     10 
     11 		both ""
     12 			#version 300 es
     13 			precision mediump float;
     14 			${DECLARATIONS}
     15 			void main()
     16 			{
     17 				out0 = 0.0;
     18 				if (in0 >= 1.0)
     19 					out0 = 1.0;
     20 				${OUTPUT}
     21 			}
     22 		""
     23 	end
     24 
     25 	case compound_statement
     26 		version 300 es
     27 		values
     28 		{
     29 			input float in0 = [ 0.0 | 1.0 | 2.0 ];
     30 			output float out0 = [ 0.0 | 1.0 | 1.0 ];
     31 			output float out1 = [ 1.0 | 0.0 | 0.0 ];
     32 		}
     33 
     34 		both ""
     35 			#version 300 es
     36 			precision mediump float;
     37 			${DECLARATIONS}
     38 			void main()
     39 			{
     40 				out0 = 0.0;
     41 				out1 = 1.0;
     42 				if (in0 >= 1.0)
     43 				{
     44 					out0 = 1.0;
     45 					out1 = 0.0;
     46 				}
     47 				${OUTPUT}
     48 			}
     49 		""
     50 	end
     51 
     52 	case sequence_statements
     53 		version 300 es
     54 		values
     55 		{
     56 			input float in0 = [ 0.0 | 1.0 | 2.0 ];
     57 			output float out0 = [ 0.0 | 1.0 | 1.0 ];
     58 			output float out1 = [ 1.0 | 0.0 | 0.0 ];
     59 		}
     60 
     61 		both ""
     62 			#version 300 es
     63 			precision mediump float;
     64 			${DECLARATIONS}
     65 			void main()
     66 			{
     67 				out0 = 0.0;
     68 				out1 = 1.0;
     69 				if (in0 >= 1.0)
     70 					out0 = 1.0, out1 = 0.0;
     71 				${OUTPUT}
     72 			}
     73 		""
     74 	end
     75 
     76 	case sequence_condition
     77 		version 300 es
     78 		values
     79 		{
     80 			input float in0 = [ 0.0 | 1.0 | 2.0 ];
     81 			output float out0 = [ 0.0 | 1.0 | 1.0 ];
     82 			output float out1 = [ 1.0 | 0.0 | 0.0 ];
     83 		}
     84 
     85 		both ""
     86 			#version 300 es
     87 			precision mediump float;
     88 			${DECLARATIONS}
     89 			void main()
     90 			{
     91 				out0 = 0.0;
     92 				out1 = 1.0;
     93 				if (false, in0 >= 1.0)
     94 					out0 = 1.0, out1 = 0.0;
     95 				${OUTPUT}
     96 			}
     97 		""
     98 	end
     99 
    100 	case complex_condition
    101 		version 300 es
    102 		values
    103 		{
    104 			input float in0 = [ 0.0 | 1.0 | 2.0 ];
    105 			output float out0 = [ 0.0 | 1.0 | 1.0 ];
    106 			output float out1 = [ 1.0 | 0.0 | 0.0 ];
    107 		}
    108 
    109 		both ""
    110 			#version 300 es
    111 			precision mediump float;
    112 			${DECLARATIONS}
    113 			void main()
    114 			{
    115 				out0 = 0.0;
    116 				out1 = 1.0;
    117 				if (false || (in0 >= 1.0) && (in0 - 2.0*in0 < 0.0))
    118 					out0 = 1.0, out1 = 0.0;
    119 				${OUTPUT}
    120 			}
    121 		""
    122 	end
    123 
    124 	case if_else
    125 		version 300 es
    126 		values
    127 		{
    128 			input float in0 = [ 0.0 | 1.0 | 2.0 ];
    129 			output float out0 = [ 0.0 | 1.0 | 1.0 ];
    130 		}
    131 
    132 		both ""
    133 			#version 300 es
    134 			precision mediump float;
    135 			${DECLARATIONS}
    136 			void main()
    137 			{
    138 				if (in0 >= 1.0)
    139 					out0 = 1.0;
    140 				else
    141 					out0 = 0.0;
    142 				${OUTPUT}
    143 			}
    144 		""
    145 	end
    146 
    147 	case if_elseif
    148 		version 300 es
    149 		values
    150 		{
    151 			input float in0 = [ 0.0 | 1.0 | 2.0 ];
    152 			output float out0 = [ 0.0 | 1.0 | 2.0 ];
    153 		}
    154 
    155 		both ""
    156 			#version 300 es
    157 			precision mediump float;
    158 			${DECLARATIONS}
    159 			void main()
    160 			{
    161 				out0 = 0.0;
    162 				if (in0 >= 2.0)
    163 					out0 = 2.0;
    164 				else if (in0 >= 1.0)
    165 					out0 = 1.0;
    166 				${OUTPUT}
    167 			}
    168 		""
    169 	end
    170 
    171 	case if_elseif_else
    172 		version 300 es
    173 		values
    174 		{
    175 			input float in0 = [ 0.0 | 1.0 | 2.0 ];
    176 			output float out0 = [ 0.0 | 1.0 | 2.0 ];
    177 		}
    178 
    179 		both ""
    180 			#version 300 es
    181 			precision mediump float;
    182 			${DECLARATIONS}
    183 			void main()
    184 			{
    185 				if (in0 >= 2.0)
    186 					out0 = 2.0;
    187 				else if (in0 >= 1.0)
    188 					out0 = 1.0;
    189 				else
    190 					out0 = 0.0;
    191 				${OUTPUT}
    192 			}
    193 		""
    194 	end
    195 
    196 	case mixed_if_elseif_else
    197 		version 300 es
    198 		values
    199 		{
    200 			input float in0 = [ 0.0 | 1.0 | 2.0 ];
    201 			output float out0 = [ 0.0 | 1.0 | 2.0 ];
    202 		}
    203 
    204 		both ""
    205 			#version 300 es
    206 			precision mediump float;
    207 			${DECLARATIONS}
    208 			void main()
    209 			{
    210 				if (in0 >= 2.0)
    211 				{
    212 					out0 = 2.0;
    213 				}
    214 				else if (in0 >= 1.0)
    215 					out0 = 2.0, out0 = 1.0;
    216 				else
    217 					out0 = 0.0;
    218 				${OUTPUT}
    219 			}
    220 		""
    221 	end
    222 
    223 end # if
    224 
    225 group invalid_if "Invalid If Conditionals"
    226 
    227 	case missing_parenthesis
    228 		version 300 es
    229 		expect compile_fail
    230 		both ""
    231 			#version 300 es
    232 			precision mediump float;
    233 			${DECLARATIONS}
    234 			void main()
    235 			{
    236 				if true
    237 					${POSITION_FRAG_COLOR} = vec4(1.0);
    238 			}
    239 		""
    240 	end
    241 
    242 	case unclosed_parenthesis
    243 		version 300 es
    244 		expect compile_fail
    245 		both ""
    246 			#version 300 es
    247 			precision mediump float;
    248 			${DECLARATIONS}
    249 			void main()
    250 			{
    251 				if (true
    252 					${POSITION_FRAG_COLOR} = vec4(1.0);
    253 			}
    254 		""
    255 	end
    256 
    257 	case int_condition
    258 		version 300 es
    259 		expect compile_fail
    260 		both ""
    261 			#version 300 es
    262 			precision mediump float;
    263 			${DECLARATIONS}
    264 			void main()
    265 			{
    266 				if (5)
    267 					${POSITION_FRAG_COLOR} = vec4(1.0);
    268 			}
    269 		""
    270 	end
    271 
    272 	case int_zero_condition
    273 		version 300 es
    274 		expect compile_fail
    275 		both ""
    276 			#version 300 es
    277 			precision mediump float;
    278 			${DECLARATIONS}
    279 			void main()
    280 			{
    281 				if (0)
    282 					${POSITION_FRAG_COLOR} = vec4(1.0);
    283 			}
    284 		""
    285 	end
    286 
    287 	case int_one_condition
    288 		version 300 es
    289 		expect compile_fail
    290 		both ""
    291 			#version 300 es
    292 			precision mediump float;
    293 			${DECLARATIONS}
    294 			void main()
    295 			{
    296 				if (1)
    297 					${POSITION_FRAG_COLOR} = vec4(1.0);
    298 			}
    299 		""
    300 	end
    301 
    302 	case int_uniform_condition
    303 		version 300 es
    304 		expect compile_fail
    305 
    306 		both ""
    307 			#version 300 es
    308 			precision mediump float;
    309 			precision mediump int;
    310 			uniform int u0;
    311 			${DECLARATIONS}
    312 			void main()
    313 			{
    314 				if (u0)
    315 					${POSITION_FRAG_COLOR} = vec4(1.0);
    316 			}
    317 		""
    318 	end
    319 
    320 	case float_condition
    321 		version 300 es
    322 		expect compile_fail
    323 		both ""
    324 			#version 300 es
    325 			precision mediump float;
    326 			${DECLARATIONS}
    327 			void main()
    328 			{
    329 				if (5.0)
    330 					${POSITION_FRAG_COLOR} = vec4(1.0);
    331 			}
    332 		""
    333 	end
    334 
    335 	case float_zero_condition
    336 		version 300 es
    337 		expect compile_fail
    338 		both ""
    339 			#version 300 es
    340 			precision mediump float;
    341 			${DECLARATIONS}
    342 			void main()
    343 			{
    344 				if (0.0)
    345 					${POSITION_FRAG_COLOR} = vec4(1.0);
    346 			}
    347 		""
    348 	end
    349 
    350 	case float_one_condition
    351 		version 300 es
    352 		expect compile_fail
    353 		both ""
    354 			#version 300 es
    355 			precision mediump float;
    356 			${DECLARATIONS}
    357 			void main()
    358 			{
    359 				if (1.0)
    360 					${POSITION_FRAG_COLOR} = vec4(1.0);
    361 			}
    362 		""
    363 	end
    364 
    365 	case sampler_condition
    366 		version 300 es
    367 		expect compile_fail
    368 		both ""
    369 			#version 300 es
    370 			precision mediump float;
    371 			uniform sampler2D s0;
    372 			${DECLARATIONS}
    373 			void main()
    374 			{
    375 				if (s0)
    376 					${POSITION_FRAG_COLOR} = vec4(1.0);
    377 			}
    378 		""
    379 	end
    380 
    381 end # invalid_if
    382