functionSemantics.frag 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #version 400
  2. uniform float u;
  3. int foo(int a, const int b, in int c, const in int d, out int e, inout int f)
  4. {
  5. int sum = a + b + c + d + f; // no e, it is out only
  6. // sum should be 47 now
  7. a *= 64;
  8. // no b, it is read only
  9. c *= 64;
  10. // no d, it is read only
  11. e = 64 * 16; // e starts undefined
  12. f *= 64;
  13. sum += a + 64 * b + c + 64 * d + e + f; // everything has a value now, totaling of 64(1+2+4+8+16+32) = 64*63 = 4032
  14. // sum should be 4032 + 47 = 4079
  15. return sum;
  16. }
  17. int foo2(float a, vec3 b, out int r)
  18. {
  19. r = int(3.0 * a);
  20. return int(5.0 * b.y);
  21. }
  22. int foo3()
  23. {
  24. if (u > 3.2) {
  25. discard;
  26. return 1000000;
  27. }
  28. return 2000000;
  29. }
  30. void main()
  31. {
  32. int e;
  33. int t = 2;
  34. struct s {
  35. ivec4 t;
  36. } f;
  37. f.t.y = 32;
  38. // test the different qualifers
  39. int color = foo(1, 2, t+t, 8, e, f.t.y);
  40. color += 128 * (e + f.t.y); // right side should be 128(64(16 + 32)) = 393216
  41. // sum should be 4079 + 393216 = 397295
  42. // test conversions
  43. float arg;
  44. float ret;
  45. ret = foo2(4, ivec3(1,2,3), arg); // ret = 10, param = 12.0
  46. color += int(ret + arg); // adds 22, for total of 397317
  47. color += foo3(); // theoretically, add 2000000, for total of 2397317
  48. gl_FragColor = vec4(color);
  49. }
  50. vec3 m(vec2);
  51. void aggCall()
  52. {
  53. float F;
  54. m(ivec2(F)); // test input conversion of single argument that's an aggregate; other function tests in 120.vert
  55. }
  56. vec4 badConv()
  57. {
  58. return u; // ERROR, can change scalar to vector
  59. }