danabr75-opengl 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +29 -0
  3. data/.gemtest +0 -0
  4. data/.gitignore +6 -0
  5. data/.travis.yml +19 -0
  6. data/Gemfile +8 -0
  7. data/History.md +101 -0
  8. data/MIT-LICENSE +18 -0
  9. data/Manifest.txt +142 -0
  10. data/README.rdoc +105 -0
  11. data/Rakefile +170 -0
  12. data/danabr75-opengl.gemspec +32 -0
  13. data/examples/NeHe/NeHe.png +0 -0
  14. data/examples/NeHe/crate.png +0 -0
  15. data/examples/NeHe/glass.png +0 -0
  16. data/examples/NeHe/nehe_lesson02.rb +117 -0
  17. data/examples/NeHe/nehe_lesson03.rb +123 -0
  18. data/examples/NeHe/nehe_lesson04.rb +132 -0
  19. data/examples/NeHe/nehe_lesson05.rb +182 -0
  20. data/examples/NeHe/nehe_lesson06.rb +186 -0
  21. data/examples/NeHe/nehe_lesson07.rb +240 -0
  22. data/examples/NeHe/nehe_lesson08.rb +255 -0
  23. data/examples/NeHe/nehe_lesson09.rb +203 -0
  24. data/examples/NeHe/nehe_lesson11.rb +176 -0
  25. data/examples/NeHe/nehe_lesson12.rb +203 -0
  26. data/examples/NeHe/nehe_lesson16.rb +211 -0
  27. data/examples/NeHe/nehe_lesson19.rb +209 -0
  28. data/examples/NeHe/nehe_lesson36.rb +308 -0
  29. data/examples/NeHe/particle.png +0 -0
  30. data/examples/NeHe/star.png +0 -0
  31. data/examples/NeHe/tim.png +0 -0
  32. data/examples/OrangeBook/3Dlabs-License.txt +33 -0
  33. data/examples/OrangeBook/brick.frag +36 -0
  34. data/examples/OrangeBook/brick.rb +378 -0
  35. data/examples/OrangeBook/brick.vert +41 -0
  36. data/examples/OrangeBook/particle.frag +17 -0
  37. data/examples/OrangeBook/particle.rb +408 -0
  38. data/examples/OrangeBook/particle.vert +38 -0
  39. data/examples/README +16 -0
  40. data/examples/RedBook/aapoly.rb +143 -0
  41. data/examples/RedBook/aargb.rb +121 -0
  42. data/examples/RedBook/accanti.rb +164 -0
  43. data/examples/RedBook/accpersp.rb +217 -0
  44. data/examples/RedBook/alpha.rb +125 -0
  45. data/examples/RedBook/alpha3D.rb +160 -0
  46. data/examples/RedBook/bezcurve.rb +107 -0
  47. data/examples/RedBook/bezmesh.rb +139 -0
  48. data/examples/RedBook/checker.rb +126 -0
  49. data/examples/RedBook/clip.rb +97 -0
  50. data/examples/RedBook/colormat.rb +137 -0
  51. data/examples/RedBook/cube.rb +71 -0
  52. data/examples/RedBook/depthcue.rb +101 -0
  53. data/examples/RedBook/dof.rb +206 -0
  54. data/examples/RedBook/double.rb +107 -0
  55. data/examples/RedBook/drawf.rb +93 -0
  56. data/examples/RedBook/feedback.rb +147 -0
  57. data/examples/RedBook/fog.rb +168 -0
  58. data/examples/RedBook/font.rb +153 -0
  59. data/examples/RedBook/hello.rb +81 -0
  60. data/examples/RedBook/image.rb +139 -0
  61. data/examples/RedBook/jitter.rb +207 -0
  62. data/examples/RedBook/light.rb +157 -0
  63. data/examples/RedBook/lines.rb +130 -0
  64. data/examples/RedBook/list.rb +113 -0
  65. data/examples/RedBook/material.rb +276 -0
  66. data/examples/RedBook/mipmap.rb +158 -0
  67. data/examples/RedBook/model.rb +115 -0
  68. data/examples/RedBook/movelight.rb +134 -0
  69. data/examples/RedBook/pickdepth.rb +181 -0
  70. data/examples/RedBook/planet.rb +110 -0
  71. data/examples/RedBook/quadric.rb +160 -0
  72. data/examples/RedBook/robot.rb +117 -0
  73. data/examples/RedBook/select.rb +198 -0
  74. data/examples/RedBook/smooth.rb +97 -0
  75. data/examples/RedBook/stencil.rb +165 -0
  76. data/examples/RedBook/stroke.rb +169 -0
  77. data/examples/RedBook/surface.rb +168 -0
  78. data/examples/RedBook/teaambient.rb +134 -0
  79. data/examples/RedBook/teapots.rb +184 -0
  80. data/examples/RedBook/tess.rb +185 -0
  81. data/examples/RedBook/texbind.rb +149 -0
  82. data/examples/RedBook/texgen.rb +171 -0
  83. data/examples/RedBook/texturesurf.rb +130 -0
  84. data/examples/RedBook/varray.rb +161 -0
  85. data/examples/RedBook/wrap.rb +150 -0
  86. data/examples/misc/OGLBench.rb +338 -0
  87. data/examples/misc/anisotropic.rb +196 -0
  88. data/examples/misc/fbo_test.rb +357 -0
  89. data/examples/misc/font-glut.rb +47 -0
  90. data/examples/misc/glfwtest.rb +30 -0
  91. data/examples/misc/plane.rb +161 -0
  92. data/examples/misc/readpixel.rb +66 -0
  93. data/examples/misc/sdltest.rb +36 -0
  94. data/examples/misc/trislam.rb +829 -0
  95. data/ext/opengl/GL/gl.h +2115 -0
  96. data/ext/opengl/GL/glext.h +11770 -0
  97. data/ext/opengl/common.h +372 -0
  98. data/ext/opengl/conv.h +247 -0
  99. data/ext/opengl/extconf.rb +19 -0
  100. data/ext/opengl/fptr_struct.h +912 -0
  101. data/ext/opengl/funcdef.h +279 -0
  102. data/ext/opengl/gl-1.0-1.1.c +3345 -0
  103. data/ext/opengl/gl-1.2.c +155 -0
  104. data/ext/opengl/gl-1.3.c +447 -0
  105. data/ext/opengl/gl-1.4.c +346 -0
  106. data/ext/opengl/gl-1.5.c +225 -0
  107. data/ext/opengl/gl-2.0.c +665 -0
  108. data/ext/opengl/gl-2.1.c +57 -0
  109. data/ext/opengl/gl-3.0.c +502 -0
  110. data/ext/opengl/gl-enums.c +4853 -0
  111. data/ext/opengl/gl-enums.h +14528 -0
  112. data/ext/opengl/gl-error.c +110 -0
  113. data/ext/opengl/gl-error.h +25 -0
  114. data/ext/opengl/gl-ext-3dfx.c +27 -0
  115. data/ext/opengl/gl-ext-arb.c +880 -0
  116. data/ext/opengl/gl-ext-ati.c +41 -0
  117. data/ext/opengl/gl-ext-ext.c +885 -0
  118. data/ext/opengl/gl-ext-gremedy.c +41 -0
  119. data/ext/opengl/gl-ext-nv.c +679 -0
  120. data/ext/opengl/gl.c +265 -0
  121. data/ext/opengl/gl_buffer.c +202 -0
  122. data/ext/opengl/glimpl.c +187 -0
  123. data/ext/opengl/glimpl.h +47 -0
  124. data/ext/opengl/opengl.c +9 -0
  125. data/lib/gl.rb +1 -0
  126. data/lib/opengl.rb +79 -0
  127. data/lib/opengl/bindings_version.rb +4 -0
  128. data/lib/opengl/implementation.rb +38 -0
  129. data/lib/opengl/test_case.rb +86 -0
  130. data/test/dummy.xorg.conf +140 -0
  131. data/test/test_gl.rb +45 -0
  132. data/test/test_gl_10_11.rb +1363 -0
  133. data/test/test_gl_12.rb +71 -0
  134. data/test/test_gl_13.rb +221 -0
  135. data/test/test_gl_14.rb +218 -0
  136. data/test/test_gl_15.rb +258 -0
  137. data/test/test_gl_20.rb +417 -0
  138. data/test/test_gl_21.rb +436 -0
  139. data/test/test_gl_ext_arb.rb +508 -0
  140. data/test/test_gl_ext_ati.rb +28 -0
  141. data/test/test_gl_ext_ext.rb +608 -0
  142. data/test/test_gl_ext_gremedy.rb +29 -0
  143. data/test/test_gl_ext_nv.rb +349 -0
  144. data/test/test_glimpl.rb +23 -0
  145. data/test/test_opengl_buffer.rb +122 -0
  146. data/utils/README +6 -0
  147. data/utils/enumgen.rb +108 -0
  148. data/utils/extlistgen.rb +90 -0
  149. metadata +326 -0
@@ -0,0 +1,436 @@
1
+ #
2
+ # Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
3
+ #
4
+ # This program is distributed under the terms of the MIT license.
5
+ # See the included MIT-LICENSE file for the terms of this license.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
8
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
9
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
10
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
11
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
12
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
13
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ #
15
+
16
+ require 'opengl/test_case'
17
+
18
+ class TestGl21 < OpenGL::TestCase
19
+
20
+ def setup
21
+ super
22
+ supported? 2.1
23
+ end
24
+
25
+ def test_gluniformmatrix21
26
+ vertex_shader_source = <<-SHADER
27
+ #version 120
28
+
29
+ uniform mat2x3 testmat23;
30
+ uniform mat3x2 testmat32;
31
+ uniform mat2x4 testmat24;
32
+ uniform mat4x2 testmat42;
33
+ uniform mat3x4 testmat34;
34
+ uniform mat4x3 testmat43;
35
+
36
+ void main() {
37
+ gl_Position = gl_Vertex *
38
+ testmat23[0].x * testmat32[0].x *
39
+ testmat24[0].x * testmat42[0].x *
40
+ testmat34[0].x * testmat43[0].x;
41
+ }
42
+ SHADER
43
+
44
+ program = glCreateProgram
45
+ vs = glCreateShader(GL_VERTEX_SHADER)
46
+
47
+ glShaderSource(vs, vertex_shader_source)
48
+ glCompileShader(vs)
49
+
50
+ assert_equal(GL_TRUE, glGetShaderiv(vs, GL_COMPILE_STATUS))
51
+ glAttachShader(program, vs)
52
+
53
+ glLinkProgram(program)
54
+ assert_equal(GL_TRUE, glGetProgramiv(program, GL_LINK_STATUS))
55
+ glUseProgram(program)
56
+
57
+ tm23l = glGetUniformLocation(program, "testmat23")
58
+ refute_equal(-1, tm23l, "testmat23 missing!")
59
+ tm32l = glGetUniformLocation(program, "testmat32")
60
+ refute_equal(-1, tm32l, "testmat32 missing!")
61
+ tm24l = glGetUniformLocation(program, "testmat24")
62
+ refute_equal(-1, tm24l, "testmat24 missing!")
63
+ tm42l = glGetUniformLocation(program, "testmat42")
64
+ refute_equal(-1, tm42l, "testmat42 missing!")
65
+ tm34l = glGetUniformLocation(program, "testmat34")
66
+ refute_equal(-1, tm34l, "testmat34 missing!")
67
+ tm43l = glGetUniformLocation(program, "testmat43")
68
+ refute_equal(-1, tm43l, "testmat43 missing!")
69
+
70
+ refute_equal(-1, glGetUniformLocation(program, "testmat23"),
71
+ "testmat23 missing!")
72
+ refute_equal(-1, glGetUniformLocation(program, "testmat32"),
73
+ "testmat32 missing!")
74
+ refute_equal(-1, glGetUniformLocation(program, "testmat24"),
75
+ "testmat24 missing!")
76
+ refute_equal(-1, glGetUniformLocation(program, "testmat42"),
77
+ "testmat42 missing!")
78
+ refute_equal(-1, glGetUniformLocation(program, "testmat34"),
79
+ "testmat34 missing!")
80
+ refute_equal(-1, glGetUniformLocation(program, "testmat43"),
81
+ "testmat43 missing!")
82
+
83
+ uniforms = Hash.new { |_, k| raise "invalid uniform #{k}" }
84
+ (0...glGetProgramiv(program, GL_ACTIVE_UNIFORMS)).each do |i|
85
+ uniform = glGetActiveUniform program, i
86
+ uniforms[uniform.last] = i
87
+ end
88
+
89
+ glUniformMatrix2x3fv(uniforms["testmat23"], GL_FALSE, [0, 1, 1, 0, 0, 1])
90
+ assert_equal([0, 1, 1, 0, 0, 1], glGetUniformfv(program, uniforms["testmat23"]))
91
+ glUniformMatrix3x2fv(uniforms["testmat32"], GL_FALSE, [1, 0, 0, 1, 1, 0])
92
+ assert_equal([1, 0, 0, 1, 1, 0], glGetUniformfv(program, uniforms["testmat32"]))
93
+
94
+ glUniformMatrix2x4fv(uniforms["testmat24"], GL_FALSE, [0, 1, 1, 0, 0, 1, 1, 0])
95
+ assert_equal([0, 1, 1, 0, 0, 1, 1, 0], glGetUniformfv(program, uniforms["testmat24"]))
96
+ glUniformMatrix4x2fv(uniforms["testmat42"], GL_FALSE, [1, 0, 0, 1, 1, 0, 0, 1])
97
+ assert_equal([1, 0, 0, 1, 1, 0, 0, 1], glGetUniformfv(program, uniforms["testmat42"]))
98
+
99
+ glUniformMatrix3x4fv(uniforms["testmat34"], GL_FALSE, [0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1])
100
+ assert_equal([0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1], glGetUniformfv(program, uniforms["testmat34"]))
101
+ glUniformMatrix4x3fv(uniforms["testmat43"], GL_FALSE, [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0])
102
+ assert_equal([1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0], glGetUniformfv(program, uniforms["testmat43"]))
103
+
104
+ # 2
105
+ m = Matrix.rows([[0, 1], [1, 0], [0, 1]])
106
+ glUniformMatrix2x3fv(uniforms["testmat23"], GL_FALSE, m)
107
+ assert_equal([0, 1, 1, 0, 0, 1], glGetUniformfv(program, uniforms["testmat23"]))
108
+ m = Matrix.rows([[0, 1, 1], [0, 0, 1]])
109
+ glUniformMatrix3x2fv(uniforms["testmat32"], GL_FALSE, m)
110
+ assert_equal([0, 1, 1, 0, 0, 1], glGetUniformfv(program, uniforms["testmat32"]))
111
+
112
+ m = Matrix.rows([[0, 1], [1, 0], [0, 1], [1, 0]])
113
+ glUniformMatrix2x4fv(uniforms["testmat24"], GL_FALSE, m)
114
+ assert_equal([0, 1, 1, 0, 0, 1, 1, 0], glGetUniformfv(program, uniforms["testmat24"]))
115
+ m = Matrix.rows([[0, 1, 1, 1], [0, 0, 1, 1]])
116
+ glUniformMatrix4x2fv(uniforms["testmat42"], GL_FALSE, m)
117
+ assert_equal([0, 1, 1, 1, 0, 0, 1, 1], glGetUniformfv(program, uniforms["testmat42"]))
118
+
119
+ m = Matrix.rows([[0, 1, 0], [1, 0, 1], [0, 1, 0], [1, 0, 1]])
120
+ glUniformMatrix3x4fv(uniforms["testmat34"], GL_FALSE, m)
121
+ assert_equal([0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], glGetUniformfv(program, uniforms["testmat34"]))
122
+
123
+ m = Matrix.rows([[0, 1, 1, 1], [0, 0, 1, 1], [1, 1, 0, 0]])
124
+ glUniformMatrix4x3fv(uniforms["testmat43"], GL_FALSE, m)
125
+ assert_equal([0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0], glGetUniformfv(program, uniforms["testmat43"]))
126
+
127
+ # 3
128
+ assert_raises ArgumentError do glUniformMatrix2x3fv(uniforms["testmat23"], GL_FALSE, [1, 2, 3, 4]) end
129
+ assert_raises ArgumentError do glUniformMatrix3x2fv(uniforms["testmat32"], GL_FALSE, [1, 2, 3, 4]) end
130
+ assert_raises ArgumentError do glUniformMatrix2x4fv(uniforms["testmat24"], GL_FALSE, [1, 2, 3, 4]) end
131
+ assert_raises ArgumentError do glUniformMatrix4x2fv(uniforms["testmat42"], GL_FALSE, [1, 2, 3, 4]) end
132
+ assert_raises ArgumentError do glUniformMatrix3x4fv(uniforms["testmat34"], GL_FALSE, [1, 2, 3, 4]) end
133
+ assert_raises ArgumentError do glUniformMatrix4x3fv(uniforms["testmat43"], GL_FALSE, [1, 2, 3, 4]) end
134
+ end
135
+
136
+ def test_pixelunpack_bitmap
137
+ skip("Segfaults on Mesa before 10") if glGetString(GL::VERSION)=~/Mesa (\d+)\.(\d+)\.(\d+)/ && $1.to_i<10
138
+ glOrtho(0, WINDOW_SIZE, 0, WINDOW_SIZE, 0, -1)
139
+
140
+ bitmap = [ 0x55 ] * 8 # 64 bits (8x8 bitmap), stipple pattern
141
+ glPixelStorei(GL_PACK_ALIGNMENT, 1)
142
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
143
+
144
+ buffers = glGenBuffers(1)
145
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
146
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 8, bitmap.pack("C*"), GL_DYNAMIC_DRAW)
147
+
148
+ glBitmap(8, 8, 0, 0, 0, 0, 0)
149
+ data = glReadPixels(0, 0, 8, 8, GL_RED, GL_UNSIGNED_BYTE)
150
+ assert_equal([0, 255] * 32, data.unpack("C*"))
151
+
152
+ glDeleteBuffers(buffers)
153
+ end
154
+
155
+ def test_pixelunpack_drawpixels
156
+ glClearColor(0, 0, 0, 0)
157
+ glClear(GL_COLOR_BUFFER_BIT)
158
+
159
+ image = ([1.0] * 3 * 16).pack("f*")
160
+
161
+ buffers = glGenBuffers(1)
162
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
163
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 3*16*4, image, GL_DYNAMIC_DRAW)
164
+
165
+ glDrawPixels(4, 4, GL_RGB, GL_FLOAT, 0)
166
+
167
+ data = glReadPixels(0, 0, 4, 4, GL_RGB, GL_FLOAT)
168
+ assert_equal(image, data)
169
+
170
+ glDeleteBuffers(buffers)
171
+ end
172
+
173
+ def test_pixelunpack_polygonstipple
174
+ stipple = ([0x12] * 128).pack("c*")
175
+ buffers = glGenBuffers(1)
176
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
177
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 128, stipple, GL_DYNAMIC_DRAW)
178
+
179
+ glPolygonStipple(0)
180
+ assert_equal(stipple, glGetPolygonStipple())
181
+ glDeleteBuffers(buffers)
182
+ end
183
+
184
+ def test_pixelunpack_texturecompression
185
+ supported?("GL_EXT_texture_compression_s3tc")
186
+
187
+ # S3TC/DXT5 compressed 2x2 pixels stipple patterns [w, b, b, w] and [b, w, w, b]
188
+ image_1 = [0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0x54, 0x5C, 0x5C].pack("C*")
189
+ image_2 = [0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x54, 0x01, 0x0D, 0x0D].pack("C*")
190
+
191
+ textures = glGenTextures(3)
192
+ glBindTexture(GL_TEXTURE_1D, textures[0])
193
+ glBindTexture(GL_TEXTURE_2D, textures[1])
194
+ glBindTexture(GL_TEXTURE_3D, textures[2])
195
+
196
+ buffers = glGenBuffers(2)
197
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
198
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 16, image_1, GL_DYNAMIC_DRAW)
199
+
200
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
201
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 16, image_2, GL_DYNAMIC_DRAW)
202
+
203
+ # Note: 1D and 3D compressed textures are not supported by S3TC/DXTn, and usually not supported at all
204
+
205
+ # 1D
206
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
207
+ begin
208
+ glCompressedTexImage1D(GL_TEXTURE_1D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 4, 0, 16, 0)
209
+ assert_equal(image_1, glGetCompressedTexImage(GL_TEXTURE_1D, 0))
210
+ rescue Gl::Error => err
211
+ assert(err.id == GL_INVALID_ENUM || err.id == GL_INVALID_OPERATION)
212
+ end
213
+
214
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
215
+ begin
216
+ glCompressedTexSubImage1D(GL_TEXTURE_1D, 0, 0, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16, 0)
217
+ assert_equal(image_2, glGetCompressedTexImage(GL_TEXTURE_1D, 0))
218
+ rescue Gl::Error => err
219
+ assert(err.id == GL_INVALID_ENUM || err.id == GL_INVALID_OPERATION)
220
+ end
221
+
222
+ # 2D
223
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
224
+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 2, 2, 0, 16, 0)
225
+ assert_equal(image_1, glGetCompressedTexImage(GL_TEXTURE_2D, 0))
226
+
227
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
228
+ glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16, 0)
229
+ assert_equal(image_2, glGetCompressedTexImage(GL_TEXTURE_2D, 0))
230
+
231
+ # 3D
232
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
233
+ begin
234
+ glCompressedTexImage3D(GL_TEXTURE_3D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 2, 2, 1, 0, 16, 0)
235
+ assert_equal(image_1, glGetCompressedTexImage(GL_TEXTURE_3D, 0))
236
+ rescue Gl::Error => err
237
+ assert(err.id == GL_INVALID_ENUM || err.id == GL_INVALID_OPERATION)
238
+ end
239
+
240
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
241
+ begin
242
+ glCompressedTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 2, 2, 1, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16, 0)
243
+ assert_equal(image_2, glGetCompressedTexImage(GL_TEXTURE_3D, 0))
244
+ rescue Gl::Error => err
245
+ assert(err.id == GL_INVALID_ENUM || err.id == GL_INVALID_OPERATION)
246
+ end
247
+
248
+ glDeleteBuffers(buffers)
249
+ glDeleteTextures(textures)
250
+ end
251
+
252
+ def test_pixelunpack_texture
253
+ textures = glGenTextures(3)
254
+ image_1 = ([0, 0, 0, 1, 1, 1] * 8).pack("f*") # 16 RGB pixels
255
+ image_2 = ([1, 1, 1, 0, 0, 0] * 8).pack("f*") # 16 RGB pixels
256
+
257
+ buffers = glGenBuffers(2)
258
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
259
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 6*8*4, image_1, GL_DYNAMIC_DRAW)
260
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
261
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 6*8*4, image_2, GL_DYNAMIC_DRAW)
262
+
263
+ # 3D
264
+ glBindTexture(GL_TEXTURE_3D, textures[0])
265
+
266
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
267
+ glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB8, 2, 2, 4, 0, GL_RGB, GL_FLOAT, 0)
268
+ assert_equal(image_1, glGetTexImage(GL_TEXTURE_3D, 0, GL_RGB, GL_FLOAT))
269
+
270
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
271
+ glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 2, 2, 4, GL_RGB, GL_FLOAT, 0)
272
+ assert_equal(image_2, glGetTexImage(GL_TEXTURE_3D, 0, GL_RGB, GL_FLOAT))
273
+
274
+ # 2D
275
+ glBindTexture(GL_TEXTURE_2D, textures[1])
276
+
277
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
278
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 4, 4, 0, GL_RGB, GL_FLOAT, 0)
279
+ assert_equal(image_1, glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT))
280
+
281
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
282
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_RGB, GL_FLOAT, 0)
283
+ assert_equal(image_2, glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT))
284
+
285
+ # 1D
286
+ glBindTexture(GL_TEXTURE_1D, textures[2])
287
+
288
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
289
+
290
+ glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB8, 16, 0, GL_RGB, GL_FLOAT, 0)
291
+ assert_equal(image_1, glGetTexImage(GL_TEXTURE_1D, 0, GL_RGB, GL_FLOAT))
292
+
293
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
294
+ glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 16, GL_RGB, GL_FLOAT, 0)
295
+ assert_equal(image_2, glGetTexImage(GL_TEXTURE_1D, 0, GL_RGB, GL_FLOAT))
296
+
297
+ glDeleteBuffers(buffers)
298
+ glDeleteTextures(textures)
299
+ end
300
+
301
+ def test_pixelunpack_pixelmap
302
+ data_1 = [1, 2, 3, 4].pack("f*")
303
+ data_2 = [5, 6, 7, 8].pack("I*")
304
+ data_3 = [9, 10, 11, 12].pack("S*")
305
+
306
+ buffers = glGenBuffers(3)
307
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
308
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 4*4+4*4+4*2, data_1+data_2+data_3, GL_DYNAMIC_DRAW)
309
+
310
+ glPixelMapfv(GL_PIXEL_MAP_I_TO_I, 4, 0)
311
+ assert_equal([1, 2, 3, 4], glGetPixelMapfv(GL_PIXEL_MAP_I_TO_I))
312
+
313
+ glPixelMapuiv(GL_PIXEL_MAP_I_TO_I, 4, 4*4)
314
+ assert_equal([5, 6, 7, 8], glGetPixelMapuiv(GL_PIXEL_MAP_I_TO_I))
315
+
316
+ glPixelMapusv(GL_PIXEL_MAP_I_TO_I, 4, 4*4+4*4)
317
+ assert_equal([9, 10, 11, 12], glGetPixelMapusv(GL_PIXEL_MAP_I_TO_I))
318
+
319
+ glDeleteBuffers(buffers)
320
+ end
321
+
322
+ def test_pixelpack_readpixels
323
+ glClearColor(0, 0, 0, 0)
324
+ glClear(GL_COLOR_BUFFER_BIT)
325
+
326
+ image = ([1.0] * 3 * 16).pack("f*")
327
+ glDrawPixels(4, 4, GL_RGB, GL_FLOAT, image)
328
+
329
+ buffers = glGenBuffers(1)
330
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
331
+ glBufferData(GL_PIXEL_PACK_BUFFER, 4*4*4*3, nil, GL_STREAM_READ)
332
+ glReadPixels(0, 0, 4, 4, GL_RGB, GL_FLOAT, 0)
333
+
334
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY)
335
+ assert_equal(image, data)
336
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER)
337
+
338
+ glDeleteBuffers(buffers)
339
+ end
340
+
341
+ def test_pixelpack_pixelmap
342
+ buffers = glGenBuffers(1)
343
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
344
+ glBufferData(GL_PIXEL_PACK_BUFFER, 4*4, nil, GL_STREAM_READ)
345
+
346
+ # fv
347
+ glPixelMapfv(GL_PIXEL_MAP_I_TO_I, [1, 2, 3, 4])
348
+ glGetPixelMapfv(GL_PIXEL_MAP_I_TO_I, 0)
349
+
350
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY)
351
+ assert_equal([1, 2, 3, 4].pack("f*"), data)
352
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER)
353
+
354
+ # uiv
355
+ glPixelMapuiv(GL_PIXEL_MAP_I_TO_I, [5, 6, 7, 8])
356
+ glGetPixelMapuiv(GL_PIXEL_MAP_I_TO_I, 0)
357
+
358
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY)
359
+ assert_equal([5, 6, 7, 8].pack("I*"), data)
360
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER)
361
+
362
+ # usv
363
+ glBufferData(GL_PIXEL_PACK_BUFFER, 4*2, nil, GL_STREAM_READ)
364
+
365
+ glPixelMapusv(GL_PIXEL_MAP_I_TO_I, [9, 10, 11, 12])
366
+ glGetPixelMapusv(GL_PIXEL_MAP_I_TO_I, 0)
367
+
368
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY)
369
+ assert_equal([9, 10, 11, 12].pack("S*"), data)
370
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER)
371
+
372
+ glDeleteBuffers(buffers)
373
+ end
374
+
375
+ def test_pixelpack_polygonstipple
376
+ stipple = [0x12] * 128
377
+
378
+ buffers = glGenBuffers(1)
379
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
380
+ glBufferData(GL_PIXEL_PACK_BUFFER, 128, nil, GL_STREAM_READ)
381
+
382
+ glPolygonStipple(stipple.pack("c*"))
383
+ glGetPolygonStipple(0)
384
+
385
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY)
386
+ assert_equal(stipple.pack("c*"), data)
387
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER)
388
+
389
+ glDeleteBuffers(buffers)
390
+ end
391
+
392
+ def test_pixelpack_teximage
393
+ textures = glGenTextures(1)
394
+ glBindTexture(GL_TEXTURE_2D, textures[0])
395
+
396
+ image = ([0, 0, 0, 1, 1, 1] * 8).pack("f*") # 16 RGB pixels
397
+
398
+ buffers = glGenBuffers(1)
399
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
400
+ glBufferData(GL_PIXEL_PACK_BUFFER, 16*3*4, nil, GL_STREAM_READ)
401
+
402
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 4, 4, 0, GL_RGB, GL_FLOAT, image)
403
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, 0)
404
+
405
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY)
406
+ assert_equal(image, data)
407
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER)
408
+
409
+ glDeleteBuffers(buffers)
410
+ glDeleteTextures(textures)
411
+ end
412
+
413
+ def test_pixelpack_compressedteximage
414
+ supported?("GL_EXT_texture_compression_s3tc")
415
+
416
+ # S3TC/DXT5 compressed 2x2 pixels stipple pattern [w, b, b, w]
417
+ image = [0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0x54, 0x5C, 0x5C].pack("C*")
418
+
419
+ textures = glGenTextures(1)
420
+ glBindTexture(GL_TEXTURE_2D, textures[0])
421
+
422
+ buffers = glGenBuffers(1)
423
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
424
+ glBufferData(GL_PIXEL_PACK_BUFFER, image.size, nil, GL_STREAM_READ)
425
+
426
+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 2, 2, 0, 16, image)
427
+ glGetCompressedTexImage(GL_TEXTURE_2D, 0, 0)
428
+
429
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY)
430
+ assert_equal(image, data)
431
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER)
432
+
433
+ glDeleteBuffers(buffers)
434
+ glDeleteTextures(textures)
435
+ end
436
+ end
@@ -0,0 +1,508 @@
1
+ #
2
+ # Copyright (C) 2007 Jan Dvorak <jan.dvorak@kraxnet.cz>
3
+ #
4
+ # This program is distributed under the terms of the MIT license.
5
+ # See the included MIT-LICENSE file for the terms of this license.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
8
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
9
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
10
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
11
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
12
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
13
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+ #
15
+
16
+ require 'opengl/test_case'
17
+
18
+ class TestGlExtArb < OpenGL::TestCase
19
+
20
+ def test_gl_arb_transpose_matrix
21
+ supported? "GL_ARB_transpose_matrix"
22
+ m_a = [[1.0, 2.0, 3.0, 4.0],
23
+ [0.0, 2.0, 0.0, 0.0],
24
+ [0.0, 0.0, 2.0, 0.0],
25
+ [0.0, 0.0, 0.0, 2.0]]
26
+
27
+ m_b = [[1.0, 2.0, 3.0, 4.0],
28
+ [0.0, 3.0, 0.0, 0.0],
29
+ [0.0, 0.0, 3.0, 0.0],
30
+ [0.0, 0.0, 0.0, 3.0]]
31
+
32
+ glMatrixMode(GL_MODELVIEW)
33
+ glLoadTransposeMatrixfARB(m_a)
34
+ assert_each_in_delta m_a, glGetDoublev(GL_TRANSPOSE_MODELVIEW_MATRIX_ARB)
35
+
36
+ glLoadTransposeMatrixdARB(m_b)
37
+ assert_each_in_delta m_b, glGetDoublev(GL_TRANSPOSE_MODELVIEW_MATRIX_ARB)
38
+
39
+ glLoadIdentity()
40
+ glMultTransposeMatrixfARB(m_a)
41
+ assert_each_in_delta m_a, glGetDoublev(GL_TRANSPOSE_MODELVIEW_MATRIX_ARB)
42
+
43
+ glLoadIdentity()
44
+ glMultTransposeMatrixdARB(m_b)
45
+ assert_each_in_delta m_b, glGetDoublev(GL_TRANSPOSE_MODELVIEW_MATRIX_ARB)
46
+
47
+ # 2
48
+ m = Matrix.rows([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
49
+ glMatrixMode(GL_MODELVIEW)
50
+ glLoadTransposeMatrixfARB(m)
51
+ assert_each_in_delta m.to_a.transpose, glGetDoublev(GL_MODELVIEW_MATRIX)
52
+ glLoadIdentity()
53
+ glLoadTransposeMatrixdARB(m)
54
+ assert_each_in_delta m.to_a.transpose, glGetDoublev(GL_MODELVIEW_MATRIX)
55
+ glLoadIdentity()
56
+ glMultTransposeMatrixfARB(m)
57
+ assert_each_in_delta m.to_a.transpose, glGetDoublev(GL_MODELVIEW_MATRIX)
58
+ glLoadIdentity()
59
+ glMultTransposeMatrixdARB(m)
60
+ assert_each_in_delta m.to_a.transpose, glGetDoublev(GL_MODELVIEW_MATRIX)
61
+
62
+ assert_raises ArgumentError do glLoadTransposeMatrixfARB([1, 2, 3, 4]) end
63
+ assert_raises ArgumentError do glLoadTransposeMatrixdARB([1, 2, 3, 4]) end
64
+ assert_raises ArgumentError do glMultTransposeMatrixfARB([1, 2, 3, 4]) end
65
+ assert_raises ArgumentError do glMultTransposeMatrixdARB([1, 2, 3, 4]) end
66
+ end
67
+
68
+ def test_gl_arb_multisample
69
+ supported? "GL_ARB_multisample"
70
+ glSampleCoverageARB(0.5, GL_FALSE)
71
+ assert_equal 0.5, glGetFloatv(GL_SAMPLE_COVERAGE_VALUE_ARB)
72
+ assert_equal false, glGetBooleanv(GL_SAMPLE_COVERAGE_INVERT_ARB)
73
+ glSampleCoverageARB(1.0, GL_TRUE)
74
+ assert_equal 1.0, glGetFloatv(GL_SAMPLE_COVERAGE_VALUE_ARB)
75
+ assert_equal true, glGetBooleanv(GL_SAMPLE_COVERAGE_INVERT_ARB)
76
+ end
77
+
78
+ def test_gl_arb_color_buffer_float
79
+ supported? "GL_ARB_color_buffer_float"
80
+ glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FIXED_ONLY_ARB)
81
+ assert_equal GL_FIXED_ONLY_ARB, glGetIntegerv(GL_CLAMP_VERTEX_COLOR_ARB)
82
+
83
+ glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_TRUE)
84
+ assert_equal GL_TRUE, glGetBooleanv(GL_CLAMP_VERTEX_COLOR_ARB)
85
+ end
86
+
87
+ def test_gl_arb_vertex_program
88
+ supported? "GL_ARB_vertex_program"
89
+
90
+ assert_equal(false, glIsProgramARB(0))
91
+ programs = glGenProgramsARB(1)
92
+ assert_equal(1, programs.size)
93
+
94
+ program = "!!ARBvp1.0\nTEMP vv;\nEND"
95
+
96
+ glBindProgramARB(GL_VERTEX_PROGRAM_ARB, programs[0])
97
+ glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, program)
98
+ assert_equal program, glGetProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_STRING_ARB)
99
+ assert_equal(glIsProgramARB(programs[0]), true)
100
+
101
+ assert_equal program.size, glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_LENGTH_ARB)
102
+ assert_equal programs[0], glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_BINDING_ARB)
103
+
104
+ glEnableVertexAttribArrayARB(1)
105
+ assert_equal GL_TRUE, glGetVertexAttribivARB(1, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB)
106
+ glDisableVertexAttribArrayARB(1)
107
+ assert_equal GL_FALSE, glGetVertexAttribivARB(1, GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB)
108
+
109
+ glVertexAttribPointerARB(1, 2, GL_FLOAT, GL_FALSE, 0, [1, 1].pack("f*"))
110
+ assert_each_in_delta([1, 1], glGetVertexAttribPointervARB(1).unpack("f*"))
111
+
112
+ glProgramEnvParameter4dARB(GL_VERTEX_PROGRAM_ARB, 1, 1, 2, 3, 4)
113
+ assert_equal([1, 2, 3, 4], glGetProgramEnvParameterdvARB(GL_VERTEX_PROGRAM_ARB, 1))
114
+ glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 1, 5, 6, 7, 8)
115
+ assert_equal([5, 6, 7, 8], glGetProgramEnvParameterfvARB(GL_VERTEX_PROGRAM_ARB, 1))
116
+ glProgramEnvParameter4dvARB(GL_VERTEX_PROGRAM_ARB, 1, [1, 2, 3, 4])
117
+ assert_equal([1, 2, 3, 4], glGetProgramEnvParameterdvARB(GL_VERTEX_PROGRAM_ARB, 1))
118
+ glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 1, [5, 6, 7, 8])
119
+ assert_equal([5, 6, 7, 8], glGetProgramEnvParameterfvARB(GL_VERTEX_PROGRAM_ARB, 1))
120
+
121
+ glProgramLocalParameter4dARB(GL_VERTEX_PROGRAM_ARB, 1, 1, 2, 3, 4)
122
+ assert_equal([1, 2, 3, 4], glGetProgramLocalParameterdvARB(GL_VERTEX_PROGRAM_ARB, 1))
123
+ glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB, 1, 5, 6, 7, 8)
124
+ assert_equal([5, 6, 7, 8], glGetProgramLocalParameterfvARB(GL_VERTEX_PROGRAM_ARB, 1))
125
+ glProgramLocalParameter4dvARB(GL_VERTEX_PROGRAM_ARB, 1, [1, 2, 3, 4])
126
+ assert_equal([1, 2, 3, 4], glGetProgramLocalParameterdvARB(GL_VERTEX_PROGRAM_ARB, 1))
127
+ glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 1, [5, 6, 7, 8])
128
+ assert_equal([5, 6, 7, 8], glGetProgramLocalParameterfvARB(GL_VERTEX_PROGRAM_ARB, 1))
129
+
130
+ glVertexAttrib1dARB(1, 1)
131
+ assert_equal(1, glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0])
132
+ glVertexAttrib1fARB(1, 2)
133
+ assert_equal(2, glGetVertexAttribfvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0])
134
+ glVertexAttrib1sARB(1, 3)
135
+ assert_equal(3, glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0])
136
+ glVertexAttrib1dvARB(1, [1])
137
+ assert_equal(1, glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0])
138
+ glVertexAttrib1fvARB(1, [2])
139
+ assert_equal(2, glGetVertexAttribfvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0])
140
+ glVertexAttrib1svARB(1, [3])
141
+ assert_equal(3, glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0])
142
+
143
+ glVertexAttrib2dARB(1, 1, 2)
144
+ assert_equal([1, 2], glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 2])
145
+ glVertexAttrib2fARB(1, 2, 3)
146
+ assert_equal([2, 3], glGetVertexAttribfvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 2])
147
+ glVertexAttrib2sARB(1, 3, 4)
148
+ assert_equal([3, 4], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 2])
149
+ glVertexAttrib2dvARB(1, [1, 2])
150
+ assert_equal([1, 2], glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 2])
151
+ glVertexAttrib2fvARB(1, [2, 3])
152
+ assert_equal([2, 3], glGetVertexAttribfvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 2])
153
+ glVertexAttrib2svARB(1, [3, 4])
154
+ assert_equal([3, 4], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 2])
155
+
156
+ glVertexAttrib3dARB(1, 1, 2, 3)
157
+ assert_equal([1, 2, 3], glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 3])
158
+ glVertexAttrib3fARB(1, 2, 3, 4)
159
+ assert_equal([2, 3, 4], glGetVertexAttribfvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 3])
160
+ glVertexAttrib3sARB(1, 3, 4, 5)
161
+ assert_equal([3, 4, 5], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 3])
162
+ glVertexAttrib3dvARB(1, [1, 2, 3])
163
+ assert_equal([1, 2, 3], glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 3])
164
+ glVertexAttrib3fvARB(1, [2, 3, 4])
165
+ assert_equal([2, 3, 4], glGetVertexAttribfvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 3])
166
+ glVertexAttrib3svARB(1, [3, 4, 5])
167
+ assert_equal([3, 4, 5], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 3])
168
+
169
+ glVertexAttrib4dARB(1, 1, 2, 3, 4)
170
+ assert_equal([1, 2, 3, 4], glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
171
+ glVertexAttrib4fARB(1, 2, 3, 4, 5)
172
+ assert_equal([2, 3, 4, 5], glGetVertexAttribfvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
173
+ glVertexAttrib4sARB(1, 3, 4, 5, 6)
174
+ assert_equal([3, 4, 5, 6], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
175
+ glVertexAttrib4dvARB(1, [1, 2, 3, 4])
176
+ assert_equal([1, 2, 3, 4], glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
177
+ glVertexAttrib4fvARB(1, [2, 3, 4, 5])
178
+ assert_equal([2, 3, 4, 5], glGetVertexAttribfvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
179
+ glVertexAttrib4svARB(1, [3, 4, 5, 6])
180
+ assert_equal([3, 4, 5, 6], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
181
+
182
+
183
+ glVertexAttrib4bvARB(1, [1, 2, 3, 4])
184
+ assert_equal([1, 2, 3, 4], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
185
+ glVertexAttrib4ivARB(1, [2, 3, 4, 5])
186
+ assert_equal([2, 3, 4, 5], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
187
+ glVertexAttrib4ubvARB(1, [3, 4, 5, 6])
188
+ assert_equal([3, 4, 5, 6], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
189
+ glVertexAttrib4uivARB(1, [1, 2, 3, 4])
190
+ assert_equal([1, 2, 3, 4], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
191
+ glVertexAttrib4usvARB(1, [2, 3, 4, 5])
192
+ assert_equal([2, 3, 4, 5], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
193
+
194
+ glVertexAttrib4NbvARB(1, [0, 2**7-1, 0, 2**7-1])
195
+ assert_equal([0, 1, 0, 1], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
196
+ glVertexAttrib4NivARB(1, [2**31-1, 0, 2**31-1, 0])
197
+ assert_equal([1, 0, 1, 0], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
198
+ glVertexAttrib4NsvARB(1, [0, 2**15-1, 0, 2**15-1])
199
+ assert_equal([0, 1, 0, 1], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
200
+
201
+ glVertexAttrib4NubARB(1, 2**8-1, 0, 2**8-1, 0)
202
+ assert_equal([1, 0, 1, 0], glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
203
+
204
+ glVertexAttrib4NubvARB(1, [0, 2**8-1, 0, 2**8-1])
205
+ assert_equal([0, 1, 0, 1], glGetVertexAttribdvARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
206
+ glVertexAttrib4NuivARB(1, [2**32-1, 0, 2**32-1, 0])
207
+ assert_equal([1, 0, 1, 0], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
208
+ glVertexAttrib4NusvARB(1, [0, 2**16-1, 0, 2**16-1])
209
+ assert_equal([0, 1, 0, 1], glGetVertexAttribivARB(1, GL_CURRENT_VERTEX_ATTRIB_ARB)[0, 4])
210
+
211
+ glDeleteProgramsARB(programs)
212
+ end
213
+
214
+ def test_gl_arb_windowpos
215
+ supported? "GL_ARB_window_pos"
216
+ # 2
217
+ glWindowPos2dARB(1.0, 2.0)
218
+ assert_each_in_delta([1, 2, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
219
+ glWindowPos2dvARB([2.0, 1.0])
220
+ assert_each_in_delta([2, 1, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
221
+ glWindowPos2fARB(1.0, 2.0)
222
+ assert_each_in_delta([1, 2, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
223
+ glWindowPos2fvARB([2.0, 1.0])
224
+ assert_each_in_delta([2, 1, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
225
+ glWindowPos2iARB(1, 2)
226
+ assert_each_in_delta([1, 2, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
227
+ glWindowPos2ivARB([2, 1])
228
+ assert_each_in_delta([2, 1, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
229
+ glWindowPos2sARB(1, 2)
230
+ assert_each_in_delta([1, 2, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
231
+ glWindowPos2svARB([2, 1])
232
+ assert_each_in_delta([2, 1, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
233
+
234
+ # 3
235
+ glWindowPos3dARB(1.0, 2.0, 0.5)
236
+ assert_each_in_delta([1, 2, 0.5, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
237
+ glWindowPos3dvARB([3.0, 2.0, 1.0])
238
+ assert_each_in_delta([3, 2, 1, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
239
+ glWindowPos3fARB(1.0, 2.0, 0.5)
240
+ assert_each_in_delta([1, 2, 0.5, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
241
+ glWindowPos3fvARB([3.0, 2.0, 1.0])
242
+ assert_each_in_delta([3, 2, 1, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
243
+ glWindowPos3iARB(1, 2, 0)
244
+ assert_each_in_delta([1, 2, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
245
+ glWindowPos3ivARB([3, 2, 1])
246
+ assert_each_in_delta([3, 2, 1, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
247
+ glWindowPos3sARB(1, 2, 0)
248
+ assert_each_in_delta([1, 2, 0, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
249
+ glWindowPos3svARB([3, 2, 1])
250
+ assert_each_in_delta([3, 2, 1, 1], glGetDoublev(GL_CURRENT_RASTER_POSITION))
251
+ end
252
+
253
+ def test_gl_arb_pointparameter
254
+ supported? "GL_ARB_point_parameters"
255
+ glPointParameterfARB(GL_POINT_SIZE_MIN, 1.0)
256
+ assert_in_delta 1.0, glGetDoublev(GL_POINT_SIZE_MIN)
257
+
258
+ glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION, [1, 0, 1])
259
+ assert_each_in_delta([1, 0, 1], glGetDoublev(GL_POINT_DISTANCE_ATTENUATION))
260
+ end
261
+
262
+ def test_gl_arb_occlusion_query
263
+ supported? "GL_ARB_occlusion_query"
264
+
265
+ queries = glGenQueriesARB(2)
266
+ assert_equal(2, queries.size)
267
+
268
+ glBeginQueryARB(GL_SAMPLES_PASSED, queries[1])
269
+ assert_equal(true, glIsQueryARB(queries[1]))
270
+
271
+ glEndQueryARB(GL_SAMPLES_PASSED)
272
+ r = glGetQueryObjectivARB(queries[1], GL_QUERY_RESULT_AVAILABLE)
273
+ assert(r==GL_TRUE || r==GL_FALSE)
274
+ assert(glGetQueryObjectuivARB(queries[1], GL_QUERY_RESULT)>=0)
275
+
276
+ glDeleteQueriesARB(queries)
277
+ assert_equal(false, glIsQueryARB(queries[1]))
278
+ end
279
+
280
+ def test_gl_arb_shader_objects
281
+ supported? "GL_ARB_shader_objects"
282
+
283
+ vertex_shader_source = "void main() { gl_Position = ftransform();}\n"
284
+
285
+ program = glCreateProgramObjectARB()
286
+
287
+ vs = glCreateShaderObjectARB(GL_VERTEX_SHADER)
288
+
289
+ glShaderSourceARB(vs, vertex_shader_source)
290
+ assert_equal vertex_shader_source, glGetShaderSourceARB(vs)
291
+
292
+ assert_equal GL_SHADER_OBJECT_ARB, glGetObjectParameterivARB(vs, GL_OBJECT_TYPE_ARB)
293
+ assert_equal GL_SHADER_OBJECT_ARB, glGetObjectParameterfvARB(vs, GL_OBJECT_TYPE_ARB)
294
+ assert_equal GL_VERTEX_SHADER, glGetObjectParameterfvARB(vs, GL_OBJECT_SUBTYPE_ARB)
295
+ glCompileShaderARB(vs)
296
+ assert_equal GL_TRUE, glGetObjectParameterivARB(vs, GL_OBJECT_COMPILE_STATUS_ARB)
297
+
298
+ vslog = glGetInfoLogARB(vs)
299
+ assert_equal(String, vslog.class)
300
+
301
+ glAttachObjectARB(program, vs)
302
+ assert_equal vs, glGetAttachedObjectsARB(program)
303
+
304
+ glLinkProgramARB(program)
305
+ assert glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB)
306
+
307
+ glValidateProgramARB(program)
308
+ assert glGetObjectParameterivARB(program, GL_OBJECT_VALIDATE_STATUS_ARB)
309
+
310
+ glUseProgramObjectARB(program)
311
+ assert_equal program, glGetIntegerv(GL_CURRENT_PROGRAM)
312
+
313
+ assert_equal program, glGetHandleARB(GL_PROGRAM_OBJECT_ARB)
314
+
315
+ glUseProgramObjectARB(0)
316
+
317
+ glDetachObjectARB(program, vs)
318
+
319
+ glDeleteObjectARB(vs)
320
+ glDeleteObjectARB(program)
321
+ end
322
+
323
+ def test_gl_arb_shader_objects_2
324
+ supported? "GL_ARB_shader_objects"
325
+
326
+ vertex_shader_source = <<-SHADER
327
+ attribute vec4 test;
328
+ uniform float testvec1;
329
+ uniform vec2 testvec2;
330
+ uniform vec3 testvec3;
331
+ uniform vec4 testvec4;
332
+ uniform int testivec1;
333
+ uniform ivec2 testivec2;
334
+ uniform ivec3 testivec3;
335
+ uniform ivec4 testivec4;
336
+
337
+ void main() {
338
+ gl_Position = ftransform() * test[0] *
339
+ testvec1 * testvec2.x * testvec3.x * testvec4.x *
340
+ float(testivec1) * float(testivec2.x) * float(testivec3.x) * float(testivec4.x);
341
+ }
342
+ SHADER
343
+
344
+ program = glCreateProgramObjectARB()
345
+ vs = glCreateShaderObjectARB(GL_VERTEX_SHADER)
346
+ glShaderSourceARB(vs, vertex_shader_source)
347
+
348
+ glCompileShaderARB(vs)
349
+ assert_equal GL_TRUE, glGetObjectParameterivARB(vs, GL_OBJECT_COMPILE_STATUS_ARB)
350
+
351
+ glAttachObjectARB(program, vs)
352
+
353
+ glLinkProgramARB(program)
354
+ assert_equal GL_TRUE, glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB)
355
+
356
+ glUseProgramObjectARB(program)
357
+
358
+ assert((tv1l = glGetUniformLocationARB(program, "testvec1"))>=0)
359
+ assert((tv2l = glGetUniformLocationARB(program, "testvec2"))>=0)
360
+ assert((tv3l = glGetUniformLocationARB(program, "testvec3"))>=0)
361
+ assert((tv4l = glGetUniformLocationARB(program, "testvec4"))>=0)
362
+ assert((tv1il = glGetUniformLocationARB(program, "testivec1"))>=0)
363
+ assert((tv2il = glGetUniformLocationARB(program, "testivec2"))>=0)
364
+ assert((tv3il = glGetUniformLocationARB(program, "testivec3"))>=0)
365
+ assert((tv4il = glGetUniformLocationARB(program, "testivec4"))>=0)
366
+
367
+ ##
368
+
369
+ assert_equal([1, GL_INT, "testivec1"], glGetActiveUniformARB(program, tv1il))
370
+
371
+ ## f
372
+ glUniform1fARB(tv1l, 2.0)
373
+ assert_equal 2.0, glGetUniformfvARB(program, tv1l)
374
+ glUniform2fARB(tv2l, 2.0, 2.0)
375
+ assert_equal([2.0, 2.0], glGetUniformfvARB(program, tv2l))
376
+ glUniform3fARB(tv3l, 2.0, 2.0, 2.0)
377
+ assert_equal([2.0, 2.0, 2.0], glGetUniformfvARB(program, tv3l))
378
+ glUniform4fARB(tv4l, 2.0, 2.0, 2.0, 2.0)
379
+ assert_equal([2.0, 2.0, 2.0, 2.0], glGetUniformfvARB(program, tv4l))
380
+ # i
381
+ glUniform1iARB(tv1il, 3)
382
+ assert_equal 3, glGetUniformivARB(program, tv1il)
383
+ glUniform2iARB(tv2il, 3, 3)
384
+ assert_equal([3, 3], glGetUniformivARB(program, tv2il))
385
+ glUniform3iARB(tv3il, 3, 3, 3)
386
+ assert_equal([3, 3, 3], glGetUniformivARB(program, tv3il))
387
+ glUniform4iARB(tv4il, 3, 3, 3, 3)
388
+ assert_equal([3, 3, 3, 3], glGetUniformivARB(program, tv4il))
389
+ # fv
390
+ glUniform1fvARB(tv1l, [3.0])
391
+ assert_equal 3.0, glGetUniformfvARB(program, tv1l)
392
+ glUniform2fvARB(tv2l, [3.0, 3.0])
393
+ assert_equal([3.0, 3.0], glGetUniformfvARB(program, tv2l))
394
+ glUniform3fvARB(tv3l, [3.0, 3.0, 3.0])
395
+ assert_equal([3.0, 3.0, 3.0], glGetUniformfvARB(program, tv3l))
396
+ glUniform4fvARB(tv4l, [3.0, 3.0, 3.0, 3.0])
397
+ assert_equal([3.0, 3.0, 3.0, 3.0], glGetUniformfvARB(program, tv4l))
398
+ # iv
399
+ glUniform1ivARB(tv1il, [2])
400
+ assert_equal 2, glGetUniformivARB(program, tv1il)
401
+ glUniform2ivARB(tv2il, [2, 2])
402
+ assert_equal([2, 2], glGetUniformivARB(program, tv2il))
403
+ glUniform3ivARB(tv3il, [2, 2, 2])
404
+ assert_equal([2, 2, 2], glGetUniformivARB(program, tv3il))
405
+ glUniform4ivARB(tv4il, [2, 2, 2, 2])
406
+ assert_equal([2, 2, 2, 2], glGetUniformivARB(program, tv4il))
407
+
408
+ glDeleteObjectARB(vs)
409
+ glDeleteObjectARB(program)
410
+ end
411
+
412
+ def test_gl_arb_shader_objects_3
413
+ supported? "GL_ARB_shader_objects"
414
+
415
+ vertex_shader_source = "uniform mat2 testmat2; uniform mat3 testmat3; uniform mat4 testmat4; void main() { gl_Position = gl_Vertex * testmat4[0].x * testmat3[0].x * testmat2[0].x;}"
416
+
417
+ program = glCreateProgramObjectARB()
418
+ vs = glCreateShaderObjectARB(GL_VERTEX_SHADER)
419
+ glShaderSourceARB(vs, vertex_shader_source)
420
+
421
+ glCompileShaderARB(vs)
422
+ assert_equal GL_TRUE, glGetObjectParameterivARB(vs, GL_OBJECT_COMPILE_STATUS_ARB)
423
+
424
+ glAttachObjectARB(program, vs)
425
+
426
+ glLinkProgramARB(program)
427
+ assert_equal GL_TRUE, glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB)
428
+
429
+ glUseProgramObjectARB(program)
430
+
431
+ refute_equal(-1, glGetUniformLocation(program, "testmat2"),
432
+ "testmat2 missing!")
433
+ refute_equal(-1, glGetUniformLocation(program, "testmat3"),
434
+ "testmat3 missing!")
435
+ refute_equal(-1, glGetUniformLocation(program, "testmat4"),
436
+ "testmat4 missing!")
437
+
438
+ uniforms = Hash.new do |_, k| raise "invalid uniform #{k}" end
439
+ (0...glGetProgramiv(program, GL_ACTIVE_UNIFORMS)).each do |i|
440
+ uniform = glGetActiveUniform program, i
441
+ uniforms[uniform.last] = i
442
+ end
443
+
444
+ glUniformMatrix2fvARB(uniforms['testmat2'], GL_TRUE, [0, 1, 2, 3])
445
+ assert_each_in_delta([0, 2, 1, 3],
446
+ glGetUniformfvARB(program, uniforms['testmat2']))
447
+
448
+ glUniformMatrix3fvARB(uniforms['testmat3'], GL_TRUE,
449
+ [0, 1, 2, 3, 4, 5, 6, 7, 8])
450
+ assert_each_in_delta([0, 3, 6, 1, 4, 7, 2, 5, 8],
451
+ glGetUniformfvARB(program, uniforms['testmat3']))
452
+
453
+ glUniformMatrix4fvARB(uniforms['testmat4'], GL_TRUE,
454
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
455
+ assert_each_in_delta([0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15],
456
+ glGetUniformfvARB(program, uniforms['testmat4']))
457
+
458
+ glDeleteObjectARB(vs)
459
+ glDeleteObjectARB(program)
460
+ end
461
+
462
+ def test_gl_arb_vertex_shader
463
+ supported? "GL_ARB_vertex_shader"
464
+
465
+ vertex_shader_source = <<-SHADER
466
+ attribute vec4 test;
467
+
468
+ uniform float testvec1;
469
+ uniform vec2 testvec2;
470
+ uniform vec3 testvec3;
471
+ uniform vec4 testvec4;
472
+
473
+ uniform int testivec1;
474
+ uniform ivec2 testivec2;
475
+ uniform ivec3 testivec3;
476
+ uniform ivec4 testivec4;
477
+
478
+ void main() {
479
+ gl_Position = ftransform() * test[0] *
480
+ testvec1 * testvec2.x * testvec3.x * testvec4.x *
481
+ float(testivec1) * float(testivec2.x) * float(testivec3.x) * float(testivec4.x);
482
+ }
483
+ SHADER
484
+
485
+ program = glCreateProgramObjectARB()
486
+ vs = glCreateShaderObjectARB(GL_VERTEX_SHADER)
487
+ glShaderSourceARB(vs, vertex_shader_source)
488
+
489
+ glCompileShaderARB(vs)
490
+ assert(glGetObjectParameterivARB(vs, GL_OBJECT_COMPILE_STATUS_ARB),
491
+ glGetInfoLogARB(vs))
492
+
493
+ glAttachObjectARB(program, vs)
494
+
495
+ glBindAttribLocationARB(program, 2, "test")
496
+
497
+ glLinkProgramARB(program)
498
+ assert_equal GL_TRUE, glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB)
499
+
500
+ glUseProgramObjectARB(program)
501
+
502
+ assert_equal 2, glGetAttribLocationARB(program, "test")
503
+ assert_equal [1, GL_FLOAT_VEC4, "gl_Vertex"], glGetActiveAttribARB(program, 0)
504
+
505
+ glDeleteObjectARB(vs)
506
+ glDeleteObjectARB(program)
507
+ end
508
+ end