opengl 0.7.0.pre1-x86-mingw32 → 0.7.0.pre2-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. data/.autotest +29 -0
  2. data/.gitignore +5 -8
  3. data/History.rdoc +33 -0
  4. data/Manifest.txt +72 -57
  5. data/README.rdoc +72 -25
  6. data/Rakefile +60 -72
  7. data/Rakefile.cross +5 -2
  8. data/{doc → docs}/build_install.txt +0 -0
  9. data/{doc → docs}/extensions.txt.in +0 -0
  10. data/{doc → docs}/history.txt +0 -0
  11. data/{doc → docs}/requirements_and_design.txt +0 -0
  12. data/{doc → docs}/roadmap.txt +0 -0
  13. data/{doc → docs}/scientific_use.txt +0 -0
  14. data/{doc → docs}/supplies/page_template.html +0 -0
  15. data/{doc → docs}/thanks.txt +0 -0
  16. data/{doc → docs}/tutorial.txt +0 -0
  17. data/examples/NeHe/NeHe.png +0 -0
  18. data/examples/NeHe/crate.png +0 -0
  19. data/examples/NeHe/glass.png +0 -0
  20. data/examples/NeHe/nehe_lesson02.rb +82 -83
  21. data/examples/NeHe/nehe_lesson03.rb +88 -88
  22. data/examples/NeHe/nehe_lesson04.rb +93 -96
  23. data/examples/NeHe/nehe_lesson05.rb +137 -144
  24. data/examples/NeHe/nehe_lesson06.rb +183 -0
  25. data/examples/NeHe/nehe_lesson07.rb +237 -0
  26. data/examples/NeHe/nehe_lesson08.rb +252 -0
  27. data/examples/NeHe/nehe_lesson09.rb +199 -0
  28. data/examples/NeHe/nehe_lesson11.rb +173 -0
  29. data/examples/NeHe/nehe_lesson12.rb +200 -0
  30. data/examples/NeHe/nehe_lesson16.rb +208 -0
  31. data/examples/NeHe/nehe_lesson19.rb +206 -0
  32. data/examples/NeHe/particle.png +0 -0
  33. data/examples/NeHe/star.png +0 -0
  34. data/examples/NeHe/tim.png +0 -0
  35. data/examples/RedBook/light.rb +154 -0
  36. data/examples/misc/OGLBench.rb +2 -2
  37. data/examples/misc/trislam.rb +2 -2
  38. data/ext/{common → opengl}/common.h +2 -11
  39. data/ext/{common → opengl}/conv.h +43 -31
  40. data/ext/{glut → opengl}/extconf.rb +14 -7
  41. data/ext/{common → opengl}/funcdef.h +155 -125
  42. data/ext/{gl → opengl}/gl-1.0-1.1.c +426 -162
  43. data/ext/{gl → opengl}/gl-1.2.c +70 -66
  44. data/ext/{gl → opengl}/gl-1.3.c +19 -19
  45. data/ext/{gl → opengl}/gl-1.4.c +23 -23
  46. data/ext/{gl → opengl}/gl-1.5.c +46 -47
  47. data/ext/{gl → opengl}/gl-2.0.c +66 -60
  48. data/ext/{gl → opengl}/gl-2.1.c +4 -4
  49. data/ext/{gl → opengl}/gl-enums.c +2 -1
  50. data/ext/{common → opengl}/gl-enums.h +0 -0
  51. data/ext/{gl → opengl}/gl-error.c +12 -4
  52. data/ext/{common → opengl}/gl-error.h +7 -2
  53. data/ext/{gl → opengl}/gl-ext-3dfx.c +1 -1
  54. data/ext/{gl → opengl}/gl-ext-arb.c +75 -70
  55. data/ext/{gl → opengl}/gl-ext-ati.c +3 -3
  56. data/ext/{gl → opengl}/gl-ext-ext.c +54 -54
  57. data/ext/{gl → opengl}/gl-ext-gremedy.c +3 -3
  58. data/ext/{gl → opengl}/gl-ext-nv.c +49 -48
  59. data/ext/{common → opengl}/gl-types.h +0 -0
  60. data/ext/{gl → opengl}/gl.c +8 -10
  61. data/ext/{glu → opengl}/glu-enums.c +1 -1
  62. data/ext/{common → opengl}/glu-enums.h +0 -0
  63. data/ext/{glu → opengl}/glu.c +7 -3
  64. data/ext/{glut → opengl}/glut.c +98 -48
  65. data/ext/opengl/opengl.c +11 -0
  66. data/lib/gl.rb +1 -0
  67. data/lib/glu.rb +1 -0
  68. data/lib/glut.rb +1 -0
  69. data/lib/opengl.rb +13 -14
  70. data/lib/opengl/opengl.so +0 -0
  71. data/lib/opengl/test_case.rb +87 -0
  72. data/test/{tc_misc.rb → test_gl.rb} +2 -14
  73. data/test/test_gl_10_11.rb +1363 -0
  74. data/test/test_gl_12.rb +182 -0
  75. data/test/{tc_func_13.rb → test_gl_13.rb} +14 -14
  76. data/test/test_gl_14.rb +221 -0
  77. data/test/test_gl_15.rb +260 -0
  78. data/test/test_gl_20.rb +430 -0
  79. data/test/test_gl_21.rb +553 -0
  80. data/test/test_gl_ext_arb.rb +526 -0
  81. data/test/{tc_ext_ati.rb → test_gl_ext_ati.rb} +11 -14
  82. data/test/test_gl_ext_ext.rb +608 -0
  83. data/test/{tc_ext_gremedy.rb → test_gl_ext_gremedy.rb} +6 -6
  84. data/test/test_gl_ext_nv.rb +352 -0
  85. data/test/test_glu.rb +309 -0
  86. metadata +159 -102
  87. data/History.txt +0 -36
  88. data/ext/gl/extconf.rb +0 -43
  89. data/ext/glu/extconf.rb +0 -51
  90. data/test/README +0 -10
  91. data/test/tc_common.rb +0 -98
  92. data/test/tc_ext_arb.rb +0 -467
  93. data/test/tc_ext_ext.rb +0 -551
  94. data/test/tc_ext_nv.rb +0 -357
  95. data/test/tc_func_10_11.rb +0 -1281
  96. data/test/tc_func_12.rb +0 -186
  97. data/test/tc_func_14.rb +0 -197
  98. data/test/tc_func_15.rb +0 -270
  99. data/test/tc_func_20.rb +0 -346
  100. data/test/tc_func_21.rb +0 -541
  101. data/test/tc_glu.rb +0 -310
  102. data/test/tc_include_gl.rb +0 -35
  103. data/test/tc_require_gl.rb +0 -34
@@ -0,0 +1,553 @@
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
+
23
+ supported? 2.1
24
+ end
25
+
26
+ def test_gluniformmatrix21
27
+ vertex_shader_source = <<-SHADER
28
+ #version 120
29
+
30
+ uniform mat2x3 testmat23;
31
+ uniform mat3x2 testmat32;
32
+ uniform mat2x4 testmat24;
33
+ uniform mat4x2 testmat42;
34
+ uniform mat3x4 testmat34;
35
+ uniform mat4x3 testmat43;
36
+
37
+ void main() {
38
+ gl_Position = gl_Vertex *
39
+ testmat23[0].x * testmat32[0].x *
40
+ testmat24[0].x * testmat42[0].x *
41
+ testmat34[0].x * testmat43[0].x;
42
+ }
43
+ SHADER
44
+
45
+ program = glCreateProgram
46
+ vs = glCreateShader(GL_VERTEX_SHADER)
47
+
48
+ glShaderSource(vs, vertex_shader_source)
49
+ glCompileShader(vs)
50
+
51
+ assert_equal(glGetShaderiv(vs, GL_COMPILE_STATUS), GL_TRUE)
52
+ glAttachShader(program, vs)
53
+
54
+ glLinkProgram(program)
55
+ assert_equal(glGetProgramiv(program, GL_LINK_STATUS), GL_TRUE)
56
+ glUseProgram(program)
57
+
58
+ tm23l = glGetUniformLocation(program, "testmat23")
59
+ refute_equal -1, tm23l, "testmat23 missing!"
60
+ tm32l = glGetUniformLocation(program, "testmat32")
61
+ refute_equal -1, tm32l, "testmat32 missing!"
62
+ tm24l = glGetUniformLocation(program, "testmat24")
63
+ refute_equal -1, tm24l, "testmat24 missing!"
64
+ tm42l = glGetUniformLocation(program, "testmat42")
65
+ refute_equal -1, tm42l, "testmat42 missing!"
66
+ tm34l = glGetUniformLocation(program, "testmat34")
67
+ refute_equal -1, tm34l, "testmat34 missing!"
68
+ tm43l = glGetUniformLocation(program, "testmat43")
69
+ refute_equal -1, tm43l, "testmat43 missing!"
70
+
71
+ refute_equal(-1, glGetUniformLocation(program, "testmat23"),
72
+ "testmat23 missing!")
73
+ refute_equal(-1, glGetUniformLocation(program, "testmat32"),
74
+ "testmat32 missing!")
75
+ refute_equal(-1, glGetUniformLocation(program, "testmat24"),
76
+ "testmat24 missing!")
77
+ refute_equal(-1, glGetUniformLocation(program, "testmat42"),
78
+ "testmat42 missing!")
79
+ refute_equal(-1, glGetUniformLocation(program, "testmat34"),
80
+ "testmat34 missing!")
81
+ refute_equal(-1, glGetUniformLocation(program, "testmat43"),
82
+ "testmat43 missing!")
83
+
84
+ uniforms = Hash.new do |_, k| raise "invalid uniform #{k}" end
85
+ (0...glGetProgramiv(program, GL_ACTIVE_UNIFORMS)).each do |i|
86
+ uniform = glGetActiveUniform program, i
87
+ uniforms[uniform.last] = i
88
+ end
89
+
90
+ skip "glUniformMatrix2x3fv complains but I don't know why"
91
+ glUniformMatrix2x3fv(uniforms["testmat23"], GL_FALSE, [0, 1, 1, 0, 0, 1])
92
+ assert_equal(glGetUniformfv(program, uniforms["testmat23"]), [0, 1, 1, 0, 0, 1])
93
+ glUniformMatrix3x2fv(uniforms["testmat32"], GL_FALSE, [1, 0, 0, 1, 1, 0])
94
+ assert_equal(glGetUniformfv(program, uniforms["testmat32"]), [1, 0, 0, 1, 1, 0])
95
+
96
+ glUniformMatrix2x4fv(uniforms["testmat24"], GL_FALSE, [0, 1, 1, 0, 0, 1, 1, 0])
97
+ assert_equal(glGetUniformfv(program, uniforms["testmat24"]), [0, 1, 1, 0, 0, 1, 1, 0])
98
+ glUniformMatrix4x2fv(uniforms["testmat42"], GL_FALSE, [1, 0, 0, 1, 1, 0, 0, 1])
99
+ assert_equal(glGetUniformfv(program, uniforms["testmat42"]), [1, 0, 0, 1, 1, 0, 0, 1])
100
+
101
+ glUniformMatrix3x4fv(uniforms["testmat34"], GL_FALSE, [0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1])
102
+ assert_equal(glGetUniformfv(program, uniforms["testmat34"]), [0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1])
103
+ glUniformMatrix4x3fv(uniforms["testmat43"], GL_FALSE, [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0])
104
+ assert_equal(glGetUniformfv(program, uniforms["testmat43"]), [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0])
105
+
106
+ # 2
107
+ m = Matrix.rows([[0, 1], [1, 0], [0, 1]])
108
+ glUniformMatrix2x3fv(uniforms["testmat23"], GL_FALSE, m)
109
+ assert_equal(glGetUniformfv(program, uniforms["testmat23"]), [0, 1, 1, 0, 0, 1])
110
+ m = Matrix.rows([[0, 1, 1], [0, 0, 1]])
111
+ glUniformMatrix3x2fv(uniforms["testmat32"], GL_FALSE, m)
112
+ assert_equal(glGetUniformfv(program, uniforms["testmat32"]), [0, 1, 1, 0, 0, 1])
113
+
114
+ m = Matrix.rows([[0, 1], [1, 0], [0, 1], [1, 0]])
115
+ glUniformMatrix2x4fv(uniforms["testmat24"], GL_FALSE, m)
116
+ assert_equal(glGetUniformfv(program, uniforms["testmat24"]), [0, 1, 1, 0, 0, 1, 1, 0])
117
+ m = Matrix.rows([[0, 1, 1, 1], [0, 0, 1, 1]])
118
+ glUniformMatrix4x2fv(uniforms["testmat42"], GL_FALSE, m)
119
+ assert_equal(glGetUniformfv(program, uniforms["testmat42"]), [0, 1, 1, 1, 0, 0, 1, 1])
120
+
121
+ m = Matrix.rows([[0, 1, 0], [1, 0, 1], [0, 1, 0], [1, 0, 1]])
122
+ glUniformMatrix3x4fv(uniforms["testmat34"], GL_FALSE, m)
123
+ assert_equal(glGetUniformfv(program, uniforms["testmat34"]), [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1])
124
+
125
+ m = Matrix.rows([[0, 1, 1, 1], [0, 0, 1, 1], [1, 1, 0, 0]])
126
+ glUniformMatrix4x3fv(uniforms["testmat43"], GL_FALSE, m)
127
+ assert_equal(glGetUniformfv(program, uniforms["testmat43"]), [0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0])
128
+
129
+ # 3
130
+ assert_raises ArgumentError do glUniformMatrix2x3fv(uniforms["testmat23"], GL_FALSE, [1, 2, 3, 4]) end
131
+ assert_raises ArgumentError do glUniformMatrix3x2fv(uniforms["testmat32"], GL_FALSE, [1, 2, 3, 4]) end
132
+ assert_raises ArgumentError do glUniformMatrix2x4fv(uniforms["testmat24"], GL_FALSE, [1, 2, 3, 4]) end
133
+ assert_raises ArgumentError do glUniformMatrix4x2fv(uniforms["testmat42"], GL_FALSE, [1, 2, 3, 4]) end
134
+ assert_raises ArgumentError do glUniformMatrix3x4fv(uniforms["testmat34"], GL_FALSE, [1, 2, 3, 4]) end
135
+ assert_raises ArgumentError do glUniformMatrix4x3fv(uniforms["testmat43"], GL_FALSE, [1, 2, 3, 4]) end
136
+ end
137
+
138
+ def test_pixelunpack_bitmap
139
+ glOrtho(0, WINDOW_SIZE, 0, WINDOW_SIZE, 0, -1)
140
+
141
+ bitmap = [ 0x55 ] * 8 # 64 bits (8x8 bitmap), stipple pattern
142
+ glPixelStorei(GL_PACK_ALIGNMENT, 1)
143
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
144
+
145
+ buffers = glGenBuffers(1)
146
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
147
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 8, bitmap.pack("C*"), GL_DYNAMIC_DRAW)
148
+
149
+ glBitmap(8, 8, 0, 0, 0, 0, 0)
150
+ data = glReadPixels(0, 0, 8, 8, GL_RED, GL_UNSIGNED_BYTE)
151
+ assert_equal(data.unpack("C*"), [0, 255] * 32)
152
+
153
+ glDeleteBuffers(buffers)
154
+ end
155
+
156
+ def test_pixelunpack_color_convolution
157
+ ct = ([0]*3+[1]*3+[0]*3+[1]*3).pack("f*")
158
+ ct2 = ([1]*3+[0]*3+[1]*3+[0]*3).pack("f*")
159
+
160
+ buffers = glGenBuffers(2)
161
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
162
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 4*3*4, ct, GL_DYNAMIC_DRAW)
163
+
164
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
165
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 4*3*4, ct2, GL_DYNAMIC_DRAW)
166
+
167
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
168
+ glColorTable(GL_COLOR_TABLE, GL_RGB8, 4, GL_RGB, GL_FLOAT, 0)
169
+ assert_equal(glGetColorTable(GL_COLOR_TABLE, GL_RGB, GL_FLOAT), ct)
170
+ glConvolutionFilter1D(GL_CONVOLUTION_1D, GL_RGB8, 4, GL_RGB, GL_FLOAT, 0)
171
+ assert_equal(glGetConvolutionFilter(GL_CONVOLUTION_1D, GL_RGB, GL_FLOAT), ct)
172
+
173
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
174
+ glColorSubTable(GL_COLOR_TABLE, 0, 4, GL_RGB, GL_FLOAT, 0)
175
+ assert_equal(glGetColorTable(GL_COLOR_TABLE, GL_RGB, GL_FLOAT), ct2)
176
+ glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGB8, 2, 2, GL_RGB, GL_FLOAT, 0)
177
+ assert_equal(glGetConvolutionFilter(GL_CONVOLUTION_2D, GL_RGB, GL_FLOAT), ct2)
178
+
179
+ glDeleteBuffers(buffers)
180
+ end
181
+
182
+ def test_pixelunpack_separable
183
+ sf_a = ([0]*3+[1]*3).pack("f*")
184
+ sf_b = ([1]*3+[0]*3).pack("f*")
185
+
186
+ buffers = glGenBuffers(1)
187
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
188
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 2*3*4 *2, sf_a + sf_b, GL_DYNAMIC_DRAW)
189
+
190
+ glSeparableFilter2D(GL_SEPARABLE_2D, GL_RGB8, 2, 2, GL_RGB, GL_FLOAT, 0, 2*3*4)
191
+ assert_equal(glGetSeparableFilter(GL_SEPARABLE_2D, GL_RGB, GL_FLOAT), [sf_a, sf_b])
192
+
193
+ glDeleteBuffers(buffers)
194
+ end
195
+
196
+ def test_pixelunpack_drawpixels
197
+ glClearColor(0, 0, 0, 0)
198
+ glClear(GL_COLOR_BUFFER_BIT)
199
+
200
+ image = ([1.0] * 3 * 16).pack("f*")
201
+
202
+ buffers = glGenBuffers(1)
203
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
204
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 3*16*4, image, GL_DYNAMIC_DRAW)
205
+
206
+ glDrawPixels(4, 4, GL_RGB, GL_FLOAT, 0)
207
+
208
+ data = glReadPixels(0, 0, 4, 4, GL_RGB, GL_FLOAT)
209
+ assert_equal(data, image)
210
+
211
+ glDeleteBuffers(buffers)
212
+ end
213
+
214
+ def test_pixelunpack_polygonstipple
215
+ stipple = ([0x12] * 128).pack("c*")
216
+ buffers = glGenBuffers(1)
217
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
218
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 128, stipple, GL_DYNAMIC_DRAW)
219
+
220
+ glPolygonStipple(0)
221
+ assert_equal(glGetPolygonStipple(), stipple)
222
+ glDeleteBuffers(buffers)
223
+ end
224
+
225
+ def test_pixelunpack_texturecompression
226
+ supported?("GL_EXT_texture_compression_s3tc")
227
+
228
+ # S3TC/DXT5 compressed 2x2 pixels stipple patterns [w, b, b, w] and [b, w, w, b]
229
+ image_1 = [0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0x54, 0x5C, 0x5C].pack("C*")
230
+ image_2 = [0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x54, 0x01, 0x0D, 0x0D].pack("C*")
231
+
232
+ textures = glGenTextures(3)
233
+ glBindTexture(GL_TEXTURE_1D, textures[0])
234
+ glBindTexture(GL_TEXTURE_2D, textures[1])
235
+ glBindTexture(GL_TEXTURE_3D, textures[2])
236
+
237
+ buffers = glGenBuffers(2)
238
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
239
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 16, image_1, GL_DYNAMIC_DRAW)
240
+
241
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
242
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 16, image_2, GL_DYNAMIC_DRAW)
243
+
244
+ # Note: 1D and 3D compressed textures are not supported by S3TC/DXTn, and usually not supported at all
245
+
246
+ # 1D
247
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
248
+ begin
249
+ glCompressedTexImage1D(GL_TEXTURE_1D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 4, 0, 16, 0)
250
+ assert_equal(glGetCompressedTexImage(GL_TEXTURE_1D, 0), image_1)
251
+ rescue Gl::Error => err
252
+ assert(err.id == GL_INVALID_ENUM || err.id == GL_INVALID_OPERATION)
253
+ end
254
+
255
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
256
+ begin
257
+ glCompressedTexSubImage1D(GL_TEXTURE_1D, 0, 0, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16, 0)
258
+ assert_equal(glGetCompressedTexImage(GL_TEXTURE_1D, 0), image_2)
259
+ rescue Gl::Error => err
260
+ assert(err.id == GL_INVALID_ENUM || err.id == GL_INVALID_OPERATION)
261
+ end
262
+
263
+ # 2D
264
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
265
+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 2, 2, 0, 16, 0)
266
+ assert_equal(glGetCompressedTexImage(GL_TEXTURE_2D, 0), image_1)
267
+
268
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
269
+ glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16, 0)
270
+ assert_equal(glGetCompressedTexImage(GL_TEXTURE_2D, 0), image_2)
271
+
272
+ # 3D
273
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
274
+ begin
275
+ glCompressedTexImage3D(GL_TEXTURE_3D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 2, 2, 1, 0, 16, 0)
276
+ assert_equal(glGetCompressedTexImage(GL_TEXTURE_3D, 0), image_1)
277
+ rescue Gl::Error => err
278
+ assert(err.id == GL_INVALID_ENUM || err.id == GL_INVALID_OPERATION)
279
+ end
280
+
281
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
282
+ begin
283
+ glCompressedTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 2, 2, 1, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16, 0)
284
+ assert_equal(glGetCompressedTexImage(GL_TEXTURE_3D, 0), image_2)
285
+ rescue Gl::Error => err
286
+ assert(err.id == GL_INVALID_ENUM || err.id == GL_INVALID_OPERATION)
287
+ end
288
+
289
+ glDeleteBuffers(buffers)
290
+ glDeleteTextures(textures)
291
+ end
292
+
293
+ def test_pixelunpack_texture
294
+ textures = glGenTextures(3)
295
+ image_1 = ([0, 0, 0, 1, 1, 1] * 8).pack("f*") # 16 RGB pixels
296
+ image_2 = ([1, 1, 1, 0, 0, 0] * 8).pack("f*") # 16 RGB pixels
297
+
298
+ buffers = glGenBuffers(2)
299
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
300
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 6*8*4, image_1, GL_DYNAMIC_DRAW)
301
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
302
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 6*8*4, image_2, GL_DYNAMIC_DRAW)
303
+
304
+ # 3D
305
+ glBindTexture(GL_TEXTURE_3D, textures[0])
306
+
307
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
308
+ glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB8, 2, 2, 4, 0, GL_RGB, GL_FLOAT, 0)
309
+ assert_equal(glGetTexImage(GL_TEXTURE_3D, 0, GL_RGB, GL_FLOAT), image_1)
310
+
311
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
312
+ glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 2, 2, 4, GL_RGB, GL_FLOAT, 0)
313
+ assert_equal(glGetTexImage(GL_TEXTURE_3D, 0, GL_RGB, GL_FLOAT), image_2)
314
+
315
+ # 2D
316
+ glBindTexture(GL_TEXTURE_2D, textures[1])
317
+
318
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
319
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 4, 4, 0, GL_RGB, GL_FLOAT, 0)
320
+ assert_equal(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT), image_1)
321
+
322
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
323
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_RGB, GL_FLOAT, 0)
324
+ assert_equal(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT), image_2)
325
+
326
+ # 1D
327
+ glBindTexture(GL_TEXTURE_1D, textures[2])
328
+
329
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
330
+
331
+ glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB8, 16, 0, GL_RGB, GL_FLOAT, 0)
332
+ assert_equal(glGetTexImage(GL_TEXTURE_1D, 0, GL_RGB, GL_FLOAT), image_1)
333
+
334
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[1])
335
+ glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 16, GL_RGB, GL_FLOAT, 0)
336
+ assert_equal(glGetTexImage(GL_TEXTURE_1D, 0, GL_RGB, GL_FLOAT), image_2)
337
+
338
+ glDeleteBuffers(buffers)
339
+ glDeleteTextures(textures)
340
+ end
341
+
342
+ def test_pixelunpack_pixelmap
343
+ data_1 = [1, 2, 3, 4].pack("f*")
344
+ data_2 = [5, 6, 7, 8].pack("I*")
345
+ data_3 = [9, 10, 11, 12].pack("S*")
346
+
347
+ buffers = glGenBuffers(3)
348
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffers[0])
349
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 4*4+4*4+4*2, data_1+data_2+data_3, GL_DYNAMIC_DRAW)
350
+
351
+ glPixelMapfv(GL_PIXEL_MAP_I_TO_I, 4, 0)
352
+ assert_equal(glGetPixelMapfv(GL_PIXEL_MAP_I_TO_I), [1, 2, 3, 4])
353
+
354
+ glPixelMapuiv(GL_PIXEL_MAP_I_TO_I, 4, 4*4)
355
+ assert_equal(glGetPixelMapuiv(GL_PIXEL_MAP_I_TO_I), [5, 6, 7, 8])
356
+
357
+ glPixelMapusv(GL_PIXEL_MAP_I_TO_I, 4, 4*4+4*4)
358
+ assert_equal(glGetPixelMapusv(GL_PIXEL_MAP_I_TO_I), [9, 10, 11, 12])
359
+
360
+ glDeleteBuffers(buffers)
361
+ end
362
+
363
+ def test_pixelpack_readpixels
364
+ glClearColor(0, 0, 0, 0)
365
+ glClear(GL_COLOR_BUFFER_BIT)
366
+
367
+ image = ([1.0] * 3 * 16).pack("f*")
368
+ glDrawPixels(4, 4, GL_RGB, GL_FLOAT, image)
369
+
370
+ buffers = glGenBuffers(1)
371
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
372
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 4*4*4*3, nil, GL_STREAM_READ)
373
+ glReadPixels(0, 0, 4, 4, GL_RGB, GL_FLOAT, 0)
374
+
375
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
376
+ assert_equal(data, image)
377
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
378
+
379
+ glDeleteBuffers(buffers)
380
+ end
381
+
382
+ def test_pixelpack_pixelmap
383
+ buffers = glGenBuffers(1)
384
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
385
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 4*4, nil, GL_STREAM_READ)
386
+
387
+ # fv
388
+ glPixelMapfv(GL_PIXEL_MAP_I_TO_I, [1, 2, 3, 4])
389
+ glGetPixelMapfv(GL_PIXEL_MAP_I_TO_I, 0)
390
+
391
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
392
+ assert_equal([1, 2, 3, 4].pack("f*"), data)
393
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
394
+
395
+ # uiv
396
+ glPixelMapuiv(GL_PIXEL_MAP_I_TO_I, [5, 6, 7, 8])
397
+ glGetPixelMapuiv(GL_PIXEL_MAP_I_TO_I, 0)
398
+
399
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
400
+ assert_equal([5, 6, 7, 8].pack("I*"), data)
401
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
402
+
403
+ # usv
404
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 4*2, nil, GL_STREAM_READ)
405
+
406
+ glPixelMapusv(GL_PIXEL_MAP_I_TO_I, [9, 10, 11, 12])
407
+ glGetPixelMapusv(GL_PIXEL_MAP_I_TO_I, 0)
408
+
409
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
410
+ assert_equal([9, 10, 11, 12].pack("S*"), data)
411
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
412
+
413
+ glDeleteBuffers(buffers)
414
+ end
415
+
416
+ def test_pixelpack_polygonstipple
417
+ stipple = [0x12] * 128
418
+
419
+ buffers = glGenBuffers(1)
420
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
421
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 128, nil, GL_STREAM_READ)
422
+
423
+ glPolygonStipple(stipple.pack("c*"))
424
+ glGetPolygonStipple(0)
425
+
426
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
427
+ assert_equal(stipple.pack("c*"), data)
428
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
429
+
430
+ glDeleteBuffers(buffers)
431
+ end
432
+
433
+ def test_pixelpack_separablefilter
434
+ sf_a = ([0]*3+[1]*3).pack("f*")
435
+ sf_b = ([1]*3+[0]*3).pack("f*")
436
+
437
+ buffers = glGenBuffers(1)
438
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
439
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 6*4 + 6*4, nil, GL_STREAM_READ)
440
+
441
+ glSeparableFilter2D(GL_SEPARABLE_2D, GL_RGB8, 2, 2, GL_RGB, GL_FLOAT, sf_a, sf_b)
442
+ glGetSeparableFilter(GL_SEPARABLE_2D, GL_RGB, GL_FLOAT, 0, 6*4, 0)
443
+
444
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
445
+ assert_equal(data, sf_a + sf_b)
446
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
447
+
448
+ glDeleteBuffers(buffers)
449
+ end
450
+
451
+ def test_pixelpack_convolutionfilter
452
+ cf = ([0]*3+[1]*3+[0]*3+[1]*3).pack("f*")
453
+
454
+ buffers = glGenBuffers(1)
455
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
456
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 3*4*4, nil, GL_STREAM_READ)
457
+
458
+ glConvolutionFilter1D(GL_CONVOLUTION_1D, GL_RGB8, 4, GL_RGB, GL_FLOAT, cf)
459
+
460
+ glGetConvolutionFilter(GL_CONVOLUTION_1D, GL_RGB, GL_FLOAT, 0)
461
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
462
+ assert_equal(data, cf)
463
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
464
+
465
+ glDeleteBuffers(buffers)
466
+ end
467
+
468
+ def test_pixelpack_histogram
469
+ glEnable(GL_HISTOGRAM)
470
+
471
+ glHistogram(GL_HISTOGRAM, 1, GL_RGB8, GL_FALSE)
472
+
473
+ buffers = glGenBuffers(1)
474
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
475
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 3*4, nil, GL_STREAM_READ)
476
+
477
+ glDrawPixels(2, 1, GL_RGB, GL_FLOAT, [1, 1, 1, 1, 1, 1].pack("f*"))
478
+ glGetHistogram(GL_HISTOGRAM, GL_FALSE, GL_RGB, GL_FLOAT, 0)
479
+
480
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
481
+ assert_equal(data.unpack("f*"), [2, 2, 2])
482
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
483
+
484
+ glDeleteBuffers(buffers)
485
+ glDisable(GL_HISTOGRAM)
486
+ end
487
+
488
+ def test_pixelpack_minmax
489
+ glEnable(GL_MINMAX)
490
+
491
+ glMinmax(GL_MINMAX, GL_RGB8, GL_FALSE)
492
+
493
+ buffers = glGenBuffers(1)
494
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
495
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 6*4, nil, GL_STREAM_READ)
496
+
497
+ glDrawPixels(2, 1, GL_RGB, GL_FLOAT, [0, 0, 0, 1, 1, 1].pack("f*"))
498
+ glGetMinmax(GL_MINMAX, GL_FALSE, GL_RGB, GL_FLOAT, 0)
499
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
500
+ assert_equal(data.unpack("f*"), [0, 0, 0, 1, 1, 1])
501
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
502
+
503
+ glDeleteBuffers(buffers)
504
+ glDisable(GL_MINMAX)
505
+ end
506
+
507
+ def test_pixelpack_teximage
508
+ textures = glGenTextures(1)
509
+ glBindTexture(GL_TEXTURE_2D, textures[0])
510
+
511
+ image = ([0, 0, 0, 1, 1, 1] * 8).pack("f*") # 16 RGB pixels
512
+
513
+ buffers = glGenBuffers(1)
514
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
515
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, 16*3*4, nil, GL_STREAM_READ)
516
+
517
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 4, 4, 0, GL_RGB, GL_FLOAT, image)
518
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, 0)
519
+
520
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
521
+ assert_equal(data, image)
522
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
523
+
524
+ glDeleteBuffers(buffers)
525
+ glDeleteTextures(textures)
526
+ end
527
+
528
+ def test_pixelpack_compressedteximage
529
+ supported?("GL_EXT_texture_compression_s3tc")
530
+
531
+ # S3TC/DXT5 compressed 2x2 pixels stipple pattern [w, b, b, w]
532
+ image = [0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0x54, 0x5C, 0x5C].pack("C*")
533
+
534
+ textures = glGenTextures(1)
535
+ glBindTexture(GL_TEXTURE_2D, textures[0])
536
+
537
+ buffers = glGenBuffers(1)
538
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, buffers[0])
539
+ glBufferData(GL_PIXEL_PACK_BUFFER_ARB, image.size, nil, GL_STREAM_READ)
540
+
541
+ glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 2, 2, 0, 16, image)
542
+ glGetCompressedTexImage(GL_TEXTURE_2D, 0, 0)
543
+
544
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY)
545
+ assert_equal(data, image)
546
+ glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB)
547
+
548
+ glDeleteBuffers(buffers)
549
+ glDeleteTextures(textures)
550
+ end
551
+
552
+ end
553
+