John Kessenich | 3a4687d | 2013-12-11 22:38:19 +0000 | [diff] [blame] | 1 | #version 110
|
| 2 |
|
| 3 | int f(int a, int b, int c)
|
| 4 | {
|
| 5 | int a = b; // ERROR, redefinition
|
| 6 |
|
| 7 | {
|
| 8 | float a = float(a) + 1.0; // okay
|
| 9 | }
|
| 10 |
|
| 11 | return a;
|
| 12 | }
|
| 13 |
|
| 14 | int f(int a, int b, int c); // okay to redeclare
|
| 15 |
|
| 16 | bool b;
|
| 17 | float b(int a); // okay, b and b() are different
|
| 18 |
|
| 19 | float c(int a);
|
| 20 | bool c; // okay, and c() are different
|
| 21 |
|
| 22 | float f; // okay f and f() are different
|
| 23 | float tan; // okay, hides built-in function
|
| 24 | float sin(float x); // okay, can redefine built-in functions
|
| 25 | float cos(float x) // okay, can redefine built-in functions
|
| 26 | {
|
| 27 | return 1.0;
|
| 28 | }
|
| 29 | bool radians(bool x) // okay, can overload built-in functions
|
| 30 | {
|
| 31 | return true;
|
| 32 | }
|
| 33 |
|
John Kessenich | 820a22f | 2015-10-06 13:11:38 -0600 | [diff] [blame] | 34 | int gi = f(1,2,3); // ERROR, can't call user-defined function from global scope
|
John Kessenich | 3a4687d | 2013-12-11 22:38:19 +0000 | [diff] [blame] | 35 |
|
| 36 | void main()
|
| 37 | {
|
| 38 | int g(); // okay
|
| 39 | g();
|
| 40 |
|
| 41 | float sin; // okay
|
| 42 | sin;
|
| 43 | sin(0.7); // okay
|
| 44 | f(1,2,3);
|
| 45 |
|
| 46 | float f;
|
| 47 | f = 3.0;
|
| 48 |
|
| 49 | gl_Position = vec4(f);
|
| 50 |
|
| 51 | for (int f = 0; f < 10; ++f)
|
| 52 | ++f;
|
| 53 |
|
| 54 | int x = 1;
|
| 55 | {
|
| 56 | float x = 2.0, /* 2nd x visible here */ y = x; // y is initialized to 2
|
| 57 | int z = z; // ERROR: z not previously defined.
|
| 58 | }
|
| 59 | {
|
| 60 | int x = x; // x is initialized to '1'
|
| 61 | }
|
| 62 |
|
| 63 | struct S
|
| 64 | {
|
| 65 | int x;
|
| 66 | };
|
| 67 | {
|
| 68 | S S = S(0); // 'S' is only visible as a struct and constructor
|
| 69 | S.x; // 'S' is now visible as a variable
|
| 70 | }
|
| 71 |
|
| 72 | int degrees;
|
| 73 | degrees(3.2);
|
John Kessenich | 2c8265b | 2018-06-11 19:25:24 -0600 | [diff] [blame] | 74 |
|
| 75 | {
|
| 76 | S s;
|
| 77 | s.x = 3;
|
| 78 | struct S { // okay, hides S
|
| 79 | bool b;
|
| 80 | };
|
| 81 | S t;
|
| 82 | t.b = true;
|
| 83 | struct S { // ERROR, redefinition of struct S
|
| 84 | float f;
|
| 85 | };
|
| 86 | }
|
John Kessenich | 3a4687d | 2013-12-11 22:38:19 +0000 | [diff] [blame] | 87 | }
|