specExamples.vert 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #version 430
  2. #extension GL_3DL_array_objects : enable
  3. out Vertex {
  4. vec4 Position; // API transform/feedback will use “Vertex.Position”
  5. vec2 Texture;
  6. } Coords; // shader will use “Coords.Position”
  7. out Vertex2 {
  8. vec4 Color; // API will use “Color”
  9. };
  10. uniform Transform { // API uses “Transform[2]” to refer to instance 2
  11. mat4 ModelViewMatrix;
  12. mat4 ModelViewProjectionMatrix;
  13. vec4 a[]; // array will get implicitly sized
  14. float Deformation;
  15. } transforms[4];
  16. layout(location = 3) in vec4 normal;
  17. layout(location = 6) in vec4 colors[3];
  18. layout(location = 9) in mat4 transforms2[2];
  19. layout(location = 3) struct S {
  20. vec3 a1;
  21. mat2 b;
  22. vec4 c[2];
  23. } s;
  24. layout(triangles, invocations = 6) in;
  25. layout(lines) in; // legal for Color2, input size is 2, matching Color2
  26. layout(triangle_strip, max_vertices = 60) out; // order does not matter
  27. layout(max_vertices = 60) out; // redeclaration okay
  28. layout(triangle_strip) out; // redeclaration okay
  29. //layout(points) out; // error, contradicts triangle_strip
  30. //layout(max_vertices = 30) out; // error, contradicts 60
  31. layout(stream = 1) out;
  32. layout(stream=1) out; // default is now stream 1
  33. out vec4 var1; // var1 gets default stream (1)
  34. layout(stream=2) out Block1 { // "Block1" belongs to stream 2
  35. layout(stream=2) vec4 var2; // redundant block member stream decl
  36. layout(stream=3) vec2 var3; // ILLEGAL (must match block stream)
  37. vec3 var4; // belongs to stream 2
  38. };
  39. layout(stream=0) out; // default is now stream 0
  40. out vec4 var5; // var5 gets default stream (0)
  41. out Block2 { // "Block2" gets default stream (0)
  42. vec4 var6;
  43. };
  44. layout(stream=3) out vec4 var7; // var7 belongs to stream 3
  45. layout(shared, column_major) uniform;
  46. layout(shared, column_major) buffer;
  47. layout(row_major, column_major)
  48. layout(shared, row_major) uniform; // default is now shared and row_major
  49. layout(std140) uniform Transform2 { // layout of this block is std140
  50. mat4 M1; // row_major
  51. layout(column_major) mat4 M2; // column major
  52. mat3 N1; // row_major
  53. };
  54. layout(column_major) uniform T3 { // shared and column_major
  55. mat4 M13; // column_major
  56. layout(row_major) mat4 m14; // row major
  57. mat3 N12; // column_major
  58. };
  59. // in one compilation unit...
  60. layout(binding=3) uniform sampler2D s17; // s bound to unit 3
  61. // in another compilation unit...
  62. uniform sampler2D s17; // okay, s still bound at 3
  63. // in another compilation unit...
  64. //layout(binding=4) uniform sampler2D s; // ERROR: contradictory bindings
  65. layout (binding = 2, offset = 4) uniform atomic_uint a2;
  66. layout (binding = 2) uniform atomic_uint bar;
  67. layout (binding = 2, offset = 4) uniform atomic_uint;
  68. layout (binding = 2) uniform atomic_uint bar; // offset is 4
  69. layout (offset = 8) uniform atomic_uint bar23; // error, no default binding
  70. layout (binding=3, offset=4) uniform atomic_uint a2; // offset = 4
  71. layout (binding=2) uniform atomic_uint b2; // offset = 0
  72. layout (binding=3) uniform atomic_uint c2; // offset = 8
  73. layout (binding=2) uniform atomic_uint d2; // offset = 4
  74. //layout (offset=4) // error, must include binding
  75. //layout (binding=1, offset=0) a; // okay
  76. //layout (binding=2, offset=0) b; // okay
  77. //layout (binding=1, offset=0) c; // error, offsets must not be shared
  78. // // between a and c
  79. //layout (binding=1, offset=2) d; // error, overlaps offset 0 of a
  80. flat in vec4 gl_FrontColor; // input to geometry shader, no “gl_in[]”
  81. flat out vec4 gl_FrontColor; // output from geometry shader
  82. invariant gl_Position; // make existing gl_Position be invariant
  83. out vec3 ColorInv;
  84. invariant ColorIvn; // make existing Color be invariant
  85. invariant centroid out vec3 Color4;
  86. precise out vec4 position;
  87. out vec3 Color5;
  88. precise Color5; // make existing Color be precise
  89. in vec4 a, b, c, d;
  90. precise out vec4 v;
  91. coherent buffer Block {
  92. readonly vec4 member1;
  93. vec4 member2;
  94. };
  95. buffer Block2a {
  96. coherent readonly vec4 member1A;
  97. coherent vec4 member2A;
  98. };
  99. shared vec4 shv;
  100. vec4 funcA(restrict image2D a) { }
  101. vec4 funcB(image2D a) { }
  102. layout(rgba32f) uniform image2D img1;
  103. layout(rgba32f) coherent uniform image2D img2;
  104. float func(float e, float f, float g, float h)
  105. {
  106. return (e*f) + (g*h); // no constraint on order or
  107. // operator consistency
  108. }
  109. float func2(float e, float f, float g, float h)
  110. {
  111. precise float result = (e*f) + (g*h); // ensures same precision for
  112. // the two multiplies
  113. return result;
  114. }
  115. float func3(float i, float j, precise out float k)
  116. {
  117. k = i * i + j; // precise, due to <k> declaration
  118. }
  119. void main()
  120. {
  121. vec3 r = vec3(a * b); // precise, used to compute v.xyz
  122. vec3 s = vec3(c * d); // precise, used to compute v.xyz
  123. v.xyz = r + s; // precise
  124. v.w = (a.w * b.w) + (c.w * d.w); // precise
  125. v.x = func(a.x, b.x, c.x, d.x); // values computed in func()
  126. // are NOT precise
  127. v.x = func2(a.x, b.x, c.x, d.x); // precise!
  128. func3(a.x * b.x, c.x * d.x, v.x); // precise!
  129. funcA(img1); // OK, adding "restrict" is allowed
  130. funcB(img2); // illegal, stripping "coherent" is not
  131. {
  132. struct light {
  133. float intensity;
  134. vec3 position;
  135. };
  136. light lightVar = light(3.0, vec3(1.0, 2.0, 3.0));
  137. }
  138. {
  139. const float c[3] = float[3](5.0, 7.2, 1.1);
  140. const float d[3] = float[](5.0, 7.2, 1.1);
  141. float g;
  142. float a[5] = float[5](g, 1, g, 2.3, g);
  143. float b[3];
  144. b = float[3](g, g + 1.0, g + 2.0);
  145. }
  146. {
  147. vec4 b[2] = { vec4(1.0), vec4(1.0) };
  148. vec4[3][2](b, b, b); // constructor
  149. vec4[][2](b, b, b); // constructor, valid, size deduced
  150. vec4[3][](b, b, b); // compile-time error, invalid type constructed
  151. }
  152. }