specExamples.frag 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #version 430
  2. #extension GL_3DL_array_objects : enable
  3. int a = 0xffffffff; // 32 bits, a gets the value -1
  4. int b = 0xffffffffU; // ERROR: can't convert uint to int
  5. uint c = 0xffffffff; // 32 bits, c gets the value 0xFFFFFFFF
  6. uint d = 0xffffffffU; // 32 bits, d gets the value 0xFFFFFFFF
  7. int e = -1; // the literal is "1", then negation is performed,
  8. // and the resulting non-literal 32-bit signed
  9. // bit pattern of 0xFFFFFFFF is assigned, giving e
  10. // the value of -1.
  11. uint f = -1u; // the literal is "1u", then negation is performed,
  12. // and the resulting non-literal 32-bit unsigned
  13. // bit pattern of 0xFFFFFFFF is assigned, giving f
  14. // the value of 0xFFFFFFFF.
  15. int g = 3000000000; // a signed decimal literal taking 32 bits,
  16. // setting the sign bit, g gets -1294967296
  17. int h = 0xA0000000; // okay, 32-bit signed hexadecimal
  18. int i = 5000000000; // ERROR: needs more than 32 bits
  19. int j = 0xFFFFFFFFF; // ERROR: needs more that 32 bits
  20. int k = 0x80000000; // k gets -2147483648 == 0x80000000
  21. int l = 2147483648; // l gets -2147483648 (the literal set the sign bit)
  22. float fa, fb = 1.5; // single-precision floating-point
  23. double fc, fd = 2.0LF; // double-precision floating-point
  24. vec2 texcoord1, texcoord2;
  25. vec3 position;
  26. vec4 myRGBA;
  27. ivec2 textureLookup;
  28. bvec3 less;
  29. mat2 mat2D;
  30. mat3 optMatrix;
  31. mat4 view, projection;
  32. mat4x4 view; // an alternate way of declaring a mat4
  33. mat3x2 m; // a matrix with 3 columns and 2 rows
  34. dmat4 highPrecisionMVP;
  35. dmat2x4 dm;
  36. struct light {
  37. float intensity;
  38. vec3 position;
  39. } lightVar;
  40. struct S { float f; };
  41. struct T {
  42. //S; // Error: anonymous structures disallowed
  43. //struct { ... }; // Error: embedded structures disallowed
  44. S s; // Okay: nested structures with name are allowed
  45. };
  46. float frequencies[3];
  47. uniform vec4 lightPosition[4];
  48. light lights[];
  49. const int numLights = 2;
  50. light lights[numLights];
  51. in vec3 normal;
  52. centroid in vec2 TexCoord;
  53. invariant centroid in vec4 Color;
  54. noperspective in float temperature;
  55. flat in vec3 myColor;
  56. noperspective centroid in vec2 myTexCoord;
  57. uniform vec4 lightPosition;
  58. uniform vec3 color = vec3(0.7, 0.7, 0.2); // value assigned at link time
  59. in Material {
  60. smooth in vec4 Color1; // legal, input inside in block
  61. smooth vec4 Color2; // legal, 'in' inherited from 'in Material'
  62. vec2 TexCoordA; // legal, TexCoord is an input
  63. uniform float Atten; // illegal, mismatched storage qualifier
  64. };
  65. in Light {
  66. vec4 LightPos;
  67. vec3 LightColor;
  68. };
  69. in ColoredTexture {
  70. vec4 Color;
  71. vec2 TexCoord;
  72. } Materiala; // instance name
  73. vec3 Color; // different Color than Material.Color
  74. in vec4 gl_FragCoord; // redeclaration that changes nothing is allowed
  75. // All the following are allowed redeclaration that change behavior
  76. layout(origin_upper_left) in vec4 gl_FragCoord;
  77. layout(pixel_center_integer) in vec4 gl_FragCoord;
  78. layout(origin_upper_left, pixel_center_integer) in vec4 gl_FragCoord;
  79. layout(early_fragment_tests) in;
  80. // compute shader:
  81. layout (local_size_x = 32, local_size_y = 32) in;
  82. layout (local_size_x = 8) in;
  83. layout(location = 3) out vec4 color;
  84. layout(location = 3, index = 1) out vec4 factor;
  85. layout(location = 2) out vec4 colors[3];
  86. layout (depth_greater) out float gl_FragDepth;
  87. // redeclaration that changes nothing is allowed
  88. out float gl_FragDepth;
  89. // assume it may be modified in any way
  90. layout (depth_any) out float gl_FragDepth;
  91. // assume it may be modified such that its value will only increase
  92. layout (depth_greater) out float gl_FragDepth;
  93. // assume it may be modified such that its value will only decrease
  94. layout (depth_less) out float gl_FragDepth;
  95. // assume it will not be modified
  96. layout (depth_unchanged) out float gl_FragDepth;
  97. in vec4 gl_Color; // predeclared by the fragment language
  98. flat in vec4 gl_Color; // redeclared by user to be flat
  99. float[5] foo(float[5])
  100. {
  101. return float[5](3.4, 4.2, 5.0, 5.2, 1.1);
  102. }
  103. precision highp float;
  104. precision highp int;
  105. precision mediump int;
  106. precision highp float;
  107. void main()
  108. {
  109. {
  110. float a[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1);
  111. }
  112. {
  113. float a[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1); // same thing
  114. }
  115. {
  116. vec4 a[3][2]; // size-3 array of size-2 array of vec4
  117. vec4[2] a1[3]; // size-3 array of size-2 array of vec4
  118. vec4[3][2] a2; // size-3 array of size-2 array of vec4
  119. vec4 b[2] = vec4[2](vec4(0.0), vec4(0.1));
  120. vec4[3][2] a3 = vec4[3][2](b, b, b); // constructor
  121. void foo(vec4[3][2]); // prototype with unnamed parameter
  122. vec4 a4[3][2] = {vec4[2](vec4(0.0), vec4(1.0)),
  123. vec4[2](vec4(0.0), vec4(1.0)),
  124. vec4[2](vec4(0.0), vec4(1.0)) };
  125. }
  126. {
  127. float a[5];
  128. {
  129. float b[] = a; // b is explicitly size 5
  130. }
  131. {
  132. float b[5] = a; // means the same thing
  133. }
  134. {
  135. float b[] = float[](1,2,3,4,5); // also explicitly sizes to 5
  136. }
  137. a.length(); // returns 5
  138. }
  139. {
  140. vec4 a[3][2];
  141. a.length(); // this is 3
  142. a[x].length(); // this is 2
  143. }
  144. // for an array b containing a member array a:
  145. b[++x].a.length(); // b is never dereferenced, but “++x” is evaluated
  146. // for an array s of a shader storage object containing a member array a:
  147. s[x].a.length(); // s is dereferenced; x needs to be a valid index
  148. //
  149. //All of the following declarations result in a compile-time error.
  150. //float a[2] = { 3.4, 4.2, 5.0 }; // illegal
  151. //vec2 b = { 1.0, 2.0, 3.0 }; // illegal
  152. //mat3x3 c = { vec3(0.0), vec3(1.0), vec3(2.0), vec3(3.0) }; // illegal
  153. //mat2x2 d = { 1.0, 0.0, 0.0, 1.0 }; // illegal, can't flatten nesting
  154. //struct {
  155. // float a;
  156. // int b;
  157. //} e = { 1.2, 2, 3 }; // illegal
  158. struct {
  159. float a;
  160. int b;
  161. } e = { 1.2, 2 }; // legal, all types match
  162. struct {
  163. float a;
  164. int b;
  165. } e = { 1, 3 }; // legal, first initializer is converted
  166. //All of the following declarations result in a compile-time error.
  167. //int a = true; // illegal
  168. //vec4 b[2] = { vec4(0.0), 1.0 }; // illegal
  169. //mat4x2 c = { vec3(0.0), vec3(1.0) }; // illegal
  170. //struct S1 {
  171. // vec4 a;
  172. // vec4 b;
  173. //};
  174. //struct {
  175. // float s;
  176. // float t;
  177. //} d[] = { S1(vec4(0.0), vec4(1.1)) }; // illegal
  178. {
  179. float a[] = float[](3.4, 4.2, 5.0, 5.2, 1.1);
  180. float b[] = { 3.4, 4.2, 5.0, 5.2, 1.1 };
  181. float c[] = a; // c is explicitly size 5
  182. float d[5] = b; // means the same thing
  183. }
  184. {
  185. const vec3 zAxis = vec3 (0.0, 0.0, 1.0);
  186. const float ceiling = a + b; // a and b not necessarily constants
  187. }
  188. {
  189. in vec4 position;
  190. in vec3 normal;
  191. in vec2 texCoord[4];
  192. }
  193. {
  194. lowp float color;
  195. out mediump vec2 P;
  196. lowp ivec2 foo(lowp mat3);
  197. highp mat4 m;
  198. }
  199. }