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

Sign up to get free protection for your applications and to get access to all the features.
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,260 @@
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 TestGl15 < OpenGL::TestCase
19
+
20
+ def setup
21
+ super
22
+
23
+ supported? 1.5
24
+ end
25
+
26
+ def test_query
27
+ queries = glGenQueries 2
28
+ assert_equal 2, queries.length
29
+
30
+ glBeginQuery GL_SAMPLES_PASSED, queries[1]
31
+ assert glIsQuery(queries[1])
32
+
33
+ glBegin GL_TRIANGLES do
34
+ glVertex2i 0, 0
35
+ glVertex2i 1, 0
36
+ glVertex2i 1, 1
37
+ end
38
+
39
+ assert_equal queries[1], glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY)
40
+
41
+ glEndQuery GL_SAMPLES_PASSED
42
+
43
+ r = glGetQueryObjectiv queries[1], GL_QUERY_RESULT_AVAILABLE
44
+ assert(r == GL_TRUE || r == GL_FALSE)
45
+
46
+ if r == GL_TRUE
47
+ assert_operator 0, :<=, glGetQueryObjectiv(queries[1], GL_QUERY_RESULT)[0]
48
+ assert_operator 0, :<=, glGetQueryObjectuiv(queries[1], GL_QUERY_RESULT)[0]
49
+ end
50
+
51
+ glDeleteQueries queries
52
+ refute glIsQuery queries[1]
53
+ end
54
+
55
+ def test_buffers
56
+ buffers = glGenBuffers(2)
57
+ glBindBuffer(GL_ARRAY_BUFFER, buffers[0])
58
+ assert glIsBuffer buffers[0]
59
+
60
+ data = [0, 1, 2, 3].pack("C*")
61
+ data2 = [4, 5, 6, 7].pack("C*")
62
+
63
+ glBufferData(GL_ARRAY_BUFFER, 4, data, GL_STREAM_READ)
64
+ assert_equal data, glGetBufferSubData(GL_ARRAY_BUFFER, 0, 4)
65
+
66
+ assert_equal GL_STREAM_READ, glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_USAGE)
67
+
68
+ glBufferSubData(GL_ARRAY_BUFFER, 0, 4, data2)
69
+ assert_equal data2, glGetBufferSubData(GL_ARRAY_BUFFER, 0, 4)
70
+
71
+ assert_equal data2, glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY)
72
+ r = glUnmapBuffer(GL_ARRAY_BUFFER)
73
+ assert(r == true || r == false)
74
+
75
+ glDeleteBuffers(buffers)
76
+ refute glIsBuffer(buffers[0])
77
+
78
+ # FIXME: GetBufferPointerv not yet implemented
79
+ end
80
+
81
+ def test_buffer_binding_element_array
82
+ glEnableClientState(GL_VERTEX_ARRAY)
83
+ va = [0, 0, 0, 1, 1, 1].pack("f*")
84
+ glVertexPointer(2, GL_FLOAT, 0, va)
85
+
86
+ #
87
+ data = [0, 1, 2].pack("C*")
88
+ buffers = glGenBuffers(1)
89
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[0])
90
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3, data, GL_DYNAMIC_DRAW)
91
+
92
+ #
93
+ feedback = glFeedbackBuffer(256, GL_3D)
94
+ glRenderMode(GL_FEEDBACK)
95
+
96
+ glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, 0)
97
+ glDrawRangeElements(GL_TRIANGLES, 0, 3, 3, GL_UNSIGNED_BYTE, 0)
98
+
99
+ count = glRenderMode(GL_RENDER)
100
+ assert_equal 22, count
101
+
102
+ glDisableClientState(GL_VERTEX_ARRAY)
103
+ glDeleteBuffers(buffers)
104
+ end
105
+
106
+ def test_buffer_binding_array_1
107
+ glEnableClientState(GL_VERTEX_ARRAY)
108
+ va = [0, 0, 0, 1, 1, 1].pack("f*")
109
+
110
+ #
111
+ buffers = glGenBuffers(1)
112
+ glBindBuffer(GL_ARRAY_BUFFER, buffers[0])
113
+ glBufferData(GL_ARRAY_BUFFER, 6*4, va, GL_DYNAMIC_DRAW)
114
+
115
+ glVertexPointer(2, GL_FLOAT, 0, 0)
116
+ assert_equal 0, glGetPointerv(GL_VERTEX_ARRAY_POINTER)
117
+ #
118
+ feedback = glFeedbackBuffer(256, GL_3D)
119
+ glRenderMode(GL_FEEDBACK)
120
+
121
+ glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, [0, 1, 2].pack("f*"))
122
+
123
+ count = glRenderMode(GL_RENDER)
124
+ assert_equal 11, count
125
+
126
+ glDeleteBuffers(buffers)
127
+ glDisableClientState(GL_VERTEX_ARRAY)
128
+ end
129
+
130
+ def test_buffer_binding_array_2
131
+ efa = [0].pack("C*")
132
+ na = [0, 1, 0].pack("f*")
133
+ ca = [1, 0, 1, 0].pack("f*")
134
+ ta = [1, 0, 1, 0].pack("f*")
135
+
136
+ buffers = glGenBuffers(4)
137
+ # load data into buffers
138
+ buffer_efa, buffer_na, buffer_ca, buffer_ta = buffers
139
+
140
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_efa)
141
+ glBufferData(GL_ARRAY_BUFFER, 1, efa, GL_DYNAMIC_DRAW)
142
+
143
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_na)
144
+ glBufferData(GL_ARRAY_BUFFER, 3*4, na, GL_DYNAMIC_DRAW)
145
+
146
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_ca)
147
+ glBufferData(GL_ARRAY_BUFFER, 4*4, ca, GL_DYNAMIC_DRAW)
148
+
149
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_ta)
150
+ glBufferData(GL_ARRAY_BUFFER, 4*4, ta, GL_DYNAMIC_DRAW)
151
+
152
+ # load buffers into arrays
153
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_na)
154
+ glEdgeFlagPointer(0, 0)
155
+ assert_equal 0, glGetPointerv(GL_EDGE_FLAG_ARRAY_POINTER)
156
+
157
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_na)
158
+ glNormalPointer(GL_FLOAT, 0, 0)
159
+ assert_equal 0, glGetPointerv(GL_NORMAL_ARRAY_POINTER)
160
+
161
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_ca)
162
+ glColorPointer(4, GL_FLOAT, 0, 0)
163
+ assert_equal 0, glGetPointerv(GL_COLOR_ARRAY_POINTER)
164
+
165
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_ta)
166
+ glTexCoordPointer(4, GL_FLOAT, 0, 0)
167
+ assert_equal 0, glGetPointerv(GL_TEXTURE_COORD_ARRAY_POINTER)
168
+
169
+ # not really testing index
170
+ glIndexPointer(GL_INT, 2, 0)
171
+ assert_equal 0, glGetPointerv(GL_INDEX_ARRAY_POINTER)
172
+
173
+ # draw arrays
174
+ glEnableClientState(GL_NORMAL_ARRAY)
175
+ glEnableClientState(GL_COLOR_ARRAY)
176
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY)
177
+ glEnableClientState(GL_EDGE_FLAG_ARRAY)
178
+
179
+ glBegin(GL_TRIANGLES)
180
+ glArrayElement(0)
181
+ glEnd()
182
+
183
+ assert_equal [0, 1, 0], glGetDoublev(GL_CURRENT_NORMAL)
184
+ assert_equal [1, 0, 1, 0], glGetDoublev(GL_CURRENT_COLOR)
185
+ assert_equal [1, 0, 1, 0], glGetDoublev(GL_CURRENT_TEXTURE_COORDS)
186
+
187
+ assert_equal GL_FALSE, glGetBooleanv(GL_EDGE_FLAG)
188
+
189
+ glDisableClientState(GL_EDGE_FLAG_ARRAY)
190
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY)
191
+ glDisableClientState(GL_COLOR_ARRAY)
192
+ glDisableClientState(GL_NORMAL_ARRAY)
193
+
194
+ glDeleteBuffers(buffers)
195
+ end
196
+
197
+ def test_buffer_binding_array_3
198
+ sc = [0, 1, 0].pack("f*")
199
+ fc = [1].pack("f*")
200
+
201
+ buffers = glGenBuffers(2)
202
+ # load data into buffers
203
+ buffer_sc, buffer_fc = buffers
204
+
205
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_sc)
206
+ glBufferData(GL_ARRAY_BUFFER, 3*4, sc, GL_DYNAMIC_DRAW)
207
+
208
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_fc)
209
+ glBufferData(GL_ARRAY_BUFFER, 1*4, fc, GL_DYNAMIC_DRAW)
210
+
211
+ # load buffers into arrays
212
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_sc)
213
+ glSecondaryColorPointer(3, GL_FLOAT, 0, 0)
214
+ assert_equal 0, glGetPointerv(GL_SECONDARY_COLOR_ARRAY_POINTER)
215
+
216
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_fc)
217
+ glFogCoordPointer(GL_FLOAT, 0, 0)
218
+ assert_equal 0, glGetPointerv(GL_FOG_COORD_ARRAY_POINTER)
219
+
220
+ # draw arrays
221
+ glEnableClientState(GL_SECONDARY_COLOR_ARRAY)
222
+ glEnableClientState(GL_FOG_COORD_ARRAY)
223
+
224
+ glBegin(GL_TRIANGLES)
225
+ glArrayElement(0)
226
+ glEnd()
227
+
228
+ assert_equal [0, 1, 0, 1], glGetDoublev(GL_CURRENT_SECONDARY_COLOR)
229
+ assert_equal 1, glGetDoublev(GL_CURRENT_FOG_COORD)
230
+
231
+ glDisableClientState(GL_SECONDARY_COLOR_ARRAY)
232
+ glDisableClientState(GL_FOG_COORD_ARRAY)
233
+
234
+ glDeleteBuffers(buffers)
235
+ end
236
+
237
+ def test_buffer_binding_array_4
238
+ va = [0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1].pack("f*")
239
+ glVertexPointer(2, GL_FLOAT, 0, va)
240
+
241
+ glEnableClientState(GL_VERTEX_ARRAY)
242
+
243
+ buf = glFeedbackBuffer(256, GL_3D)
244
+ glRenderMode(GL_FEEDBACK)
245
+
246
+ data = [0, 1, 2, 3, 4, 5]
247
+ buffers = glGenBuffers(3)
248
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[0])
249
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6, data.pack("C*"), GL_DYNAMIC_DRAW)
250
+
251
+ glMultiDrawElements(GL_TRIANGLES, GL_UNSIGNED_BYTE, [3, 3], [0, 3])
252
+
253
+ count = glRenderMode(GL_RENDER)
254
+ assert_equal 2 * (3 * 3 + 2), count
255
+
256
+ glDisableClientState(GL_VERTEX_ARRAY)
257
+ glDeleteBuffers(buffers)
258
+ end
259
+
260
+ end
@@ -0,0 +1,430 @@
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 TestGl20 < OpenGL::TestCase
19
+
20
+ def setup
21
+ super
22
+
23
+ supported? 2.0
24
+ end
25
+
26
+ def test_glblendequationseparate
27
+ glBlendEquationSeparate(GL_MIN, GL_MAX)
28
+ assert_equal(glGetIntegerv(GL_BLEND_EQUATION_RGB), GL_MIN)
29
+ assert_equal(glGetIntegerv(GL_BLEND_EQUATION_ALPHA), GL_MAX)
30
+ glBlendEquationSeparate(GL_MAX, GL_MIN)
31
+ assert_equal(glGetIntegerv(GL_BLEND_EQUATION_RGB), GL_MAX)
32
+ assert_equal(glGetIntegerv(GL_BLEND_EQUATION_ALPHA), GL_MIN)
33
+ end
34
+
35
+ def test_stencilops
36
+ glStencilOpSeparate(GL_FRONT, GL_ZERO, GL_INCR, GL_DECR)
37
+ assert_equal(glGetIntegerv(GL_STENCIL_FAIL), GL_ZERO)
38
+ assert_equal(glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL), GL_INCR)
39
+ assert_equal(glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS), GL_DECR)
40
+ glStencilOpSeparate(GL_FRONT, GL_INCR, GL_DECR, GL_ZERO)
41
+ assert_equal(glGetIntegerv(GL_STENCIL_FAIL), GL_INCR)
42
+ assert_equal(glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL), GL_DECR)
43
+ assert_equal(glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS), GL_ZERO)
44
+
45
+ glStencilFuncSeparate(GL_FRONT, GL_LEQUAL, 1, 0)
46
+ assert_equal(glGetIntegerv(GL_STENCIL_FUNC), GL_LEQUAL)
47
+ assert_equal(glGetIntegerv(GL_STENCIL_REF), 1)
48
+ assert_equal(glGetIntegerv(GL_STENCIL_VALUE_MASK), 0)
49
+ glStencilFuncSeparate(GL_FRONT, GL_GEQUAL, 0, 1)
50
+ assert_equal(glGetIntegerv(GL_STENCIL_FUNC), GL_GEQUAL)
51
+ assert_equal(glGetIntegerv(GL_STENCIL_REF), 0)
52
+ assert_equal(glGetIntegerv(GL_STENCIL_VALUE_MASK), 1)
53
+
54
+ glStencilMaskSeparate(GL_FRONT, 1)
55
+ assert_equal(glGetIntegerv( GL_STENCIL_WRITEMASK), 1)
56
+ glStencilMaskSeparate(GL_FRONT, 0)
57
+ assert_equal(glGetIntegerv(GL_STENCIL_WRITEMASK), 0)
58
+ end
59
+
60
+ def test_gldrawbuf
61
+ glDrawBuffers([GL_FRONT_LEFT, GL_BACK_LEFT])
62
+ assert_equal(glGetIntegerv(GL_DRAW_BUFFER0), GL_FRONT_LEFT)
63
+ assert_equal(glGetIntegerv(GL_DRAW_BUFFER1), GL_BACK_LEFT)
64
+ end
65
+
66
+ def test_glvertexattrib
67
+ # 1
68
+ glVertexAttrib1d(1, 2.0)
69
+ assert_equal([2.0, 0.0, 0.0, 1.0], glGetVertexAttribdv(1, GL_CURRENT_VERTEX_ATTRIB))
70
+ glVertexAttrib1dv(1, [3.0])
71
+ assert_equal([3.0, 0.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
72
+ glVertexAttrib1f(1, 2.0)
73
+ assert_equal([2, 0, 0, 1], glGetVertexAttribiv(1, GL_CURRENT_VERTEX_ATTRIB))
74
+ glVertexAttrib1fv(1, [3.0])
75
+ assert_equal([3.0, 0.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
76
+ glVertexAttrib1s(1, 2)
77
+ assert_equal([2.0, 0.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
78
+ glVertexAttrib1sv(1, [3])
79
+ assert_equal([3.0, 0.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
80
+ # 2
81
+ glVertexAttrib2d(1, 2.0, 2.0)
82
+ assert_equal([2.0, 2.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
83
+ glVertexAttrib2dv(1, [3.0, 3.0])
84
+ assert_equal([3.0, 3.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
85
+ glVertexAttrib2f(1, 2.0, 2.0)
86
+ assert_equal([2.0, 2.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
87
+ glVertexAttrib2fv(1, [3.0, 3.0])
88
+ assert_equal([3.0, 3.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
89
+ glVertexAttrib2s(1, 2, 2)
90
+ assert_equal([2.0, 2.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
91
+ glVertexAttrib2sv(1, [3, 3])
92
+ assert_equal([3.0, 3.0, 0.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
93
+ # 3
94
+ glVertexAttrib3d(1, 2.0, 2.0, 2.0)
95
+ assert_equal([2.0, 2.0, 2.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
96
+ glVertexAttrib3dv(1, [3.0, 3.0, 3.0])
97
+ assert_equal([3.0, 3.0, 3.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
98
+ glVertexAttrib3f(1, 2.0, 2.0, 2.0)
99
+ assert_equal([2.0, 2.0, 2.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
100
+ glVertexAttrib3fv(1, [3.0, 3.0, 3.0])
101
+ assert_equal([3.0, 3.0, 3.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
102
+ glVertexAttrib3s(1, 2, 2, 2)
103
+ assert_equal([2.0, 2.0, 2.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
104
+ glVertexAttrib3sv(1, [3, 3, 3])
105
+ assert_equal([3.0, 3.0, 3.0, 1.0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
106
+ # 4N
107
+ glVertexAttrib4Nbv(1, [2**7-1, 2**7-1, 2**7-1, 2**7-1])
108
+ assert_each_in_delta([1, 1, 1, 1], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
109
+ glVertexAttrib4Niv(1, [0, 0, 0, 0])
110
+ assert_each_in_delta([0, 0, 0, 0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
111
+ glVertexAttrib4Nsv(1, [2**15-1, 2**15-1, 2**15-1, 2**15-1])
112
+ assert_each_in_delta([1, 1, 1, 1], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
113
+ glVertexAttrib4Nub(1, 0, 0, 0, 0)
114
+ assert_each_in_delta([0, 0, 0, 0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
115
+ glVertexAttrib4Nubv(1, [2**8-1, 2**8-1, 2**8-1, 2**8-1])
116
+ assert_each_in_delta([1, 1, 1, 1], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
117
+ glVertexAttrib4Nuiv(1, [0, 0, 0, 0])
118
+ assert_each_in_delta([0, 0, 0, 0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
119
+ glVertexAttrib4Nusv(1, [2**16-1, 2**16-1, 2**16-1, 2**16-1])
120
+ assert_each_in_delta([1, 1, 1, 1], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
121
+ # 4
122
+ glVertexAttrib4bv(1, [0, 0, 0, 0])
123
+ assert_each_in_delta([0, 0, 0, 0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
124
+ glVertexAttrib4d(1, 1, 1, 1, 1)
125
+ assert_each_in_delta([1, 1, 1, 1], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
126
+ glVertexAttrib4dv(1, [0, 0, 0, 0])
127
+ assert_each_in_delta([0, 0, 0, 0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
128
+ glVertexAttrib4f(1, 1, 1, 1, 1)
129
+ assert_each_in_delta([1, 1, 1, 1], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
130
+ glVertexAttrib4fv(1, [0, 0, 0, 0])
131
+ assert_each_in_delta([0, 0, 0, 0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
132
+ glVertexAttrib4iv(1, [1, 1, 1, 1])
133
+ assert_each_in_delta([1, 1, 1, 1], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
134
+ glVertexAttrib4s(1, 0, 0, 0, 0)
135
+ assert_each_in_delta([0, 0, 0, 0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
136
+ glVertexAttrib4sv(1, [1, 1, 1, 1])
137
+ assert_each_in_delta([1, 1, 1, 1], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
138
+ glVertexAttrib4ubv(1, [0, 0, 0, 0])
139
+ assert_each_in_delta([0, 0, 0, 0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
140
+ glVertexAttrib4uiv(1, [1, 1, 1, 1])
141
+ assert_each_in_delta([1, 1, 1, 1], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
142
+ glVertexAttrib4usv(1, [0, 0, 0, 0])
143
+ assert_each_in_delta([0, 0, 0, 0], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
144
+ end
145
+
146
+ def test_vertexattribpointer
147
+ vaa = [1, 1, 1, 1, 2, 2, 2, 2].pack("f*")
148
+ glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, vaa)
149
+ assert_equal(glGetVertexAttribPointerv(1), vaa)
150
+
151
+ glEnableVertexAttribArray(1)
152
+
153
+ glBegin(GL_POINTS)
154
+ glArrayElement(1)
155
+ glEnd()
156
+ assert_equal([2, 2, 2, 2], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
157
+
158
+ glDisableVertexAttribArray(1)
159
+ end
160
+
161
+ def test_shaders
162
+ vertex_shader_source = <<-SHADER
163
+ #version 110
164
+
165
+ void main() {
166
+ gl_Position = ftransform();
167
+ }
168
+ SHADER
169
+
170
+ program = glCreateProgram
171
+ assert glIsProgram program
172
+
173
+ vs = glCreateShader GL_VERTEX_SHADER
174
+ assert glIsShader vs
175
+
176
+ glShaderSource vs, vertex_shader_source
177
+ assert_equal vertex_shader_source, glGetShaderSource(vs)
178
+ assert_equal GL_VERTEX_SHADER, glGetShaderiv(vs, GL_SHADER_TYPE)
179
+
180
+ glCompileShader vs
181
+ assert glGetShaderiv(vs, GL_COMPILE_STATUS)
182
+
183
+ vslog = glGetShaderInfoLog vs
184
+ assert_equal '', vslog
185
+
186
+ glAttachShader program, vs
187
+ assert_equal vs, glGetAttachedShaders(program)
188
+
189
+ glDetachShader program, vs
190
+ assert_nil glGetAttachedShaders program
191
+
192
+ glAttachShader program, vs
193
+
194
+ glLinkProgram program
195
+ assert glGetProgramiv(program, GL_LINK_STATUS)
196
+
197
+ glValidateProgram program
198
+ assert(glGetProgramiv(program, GL_VALIDATE_STATUS),
199
+ glGetProgramInfoLog(program))
200
+
201
+ prlog = glGetProgramInfoLog program
202
+ assert_equal '', prlog
203
+
204
+ glUseProgram program
205
+ assert_equal program, glGetIntegerv(GL_CURRENT_PROGRAM)
206
+
207
+ glUseProgram 0
208
+
209
+ glDetachShader program, vs
210
+ glDeleteShader vs
211
+ refute glIsShader vs
212
+
213
+ glDeleteProgram program
214
+ refute glIsProgram(program)
215
+ end
216
+
217
+ def test_shaders_2
218
+ vertex_shader_source = <<-SHADER
219
+ #version 110
220
+ attribute vec4 test;
221
+
222
+ uniform float testvec1;
223
+ uniform vec2 testvec2;
224
+ uniform vec3 testvec3;
225
+ uniform vec4 testvec4;
226
+
227
+ uniform int testivec1;
228
+ uniform ivec2 testivec2;
229
+ uniform ivec3 testivec3;
230
+ uniform ivec4 testivec4;
231
+
232
+ void main() {
233
+ testvec1;
234
+ testvec2;
235
+ testvec3;
236
+ testvec4;
237
+ testivec1;
238
+ testivec2;
239
+ testivec3;
240
+ testivec4;
241
+ gl_Position = ftransform();
242
+ }
243
+ SHADER
244
+
245
+ program = glCreateProgram
246
+
247
+ vs = glCreateShader GL_VERTEX_SHADER
248
+
249
+ glShaderSource vs, vertex_shader_source
250
+ glCompileShader vs
251
+
252
+ assert glGetShaderiv(vs, GL_COMPILE_STATUS), glGetShaderInfoLog(vs)
253
+
254
+ glAttachShader program, vs
255
+
256
+ glBindAttribLocation program, 2, "test"
257
+ glLinkProgram program
258
+
259
+ glValidateProgram program
260
+ assert(glGetProgramiv(program, GL_VALIDATE_STATUS),
261
+ glGetProgramInfoLog(program))
262
+
263
+ assert glGetProgramiv(program, GL_LINK_STATUS)
264
+
265
+ glUseProgram program
266
+
267
+ test = glGetAttribLocation program, "test"
268
+ assert_equal -1, test
269
+
270
+ tv1l = glGetUniformLocation program, "testvec1"
271
+ refute_equal -1, tv1l, "testvec1 missing!"
272
+
273
+ tv2l = glGetUniformLocation program, "testvec2"
274
+ refute_equal -1, tv2l, "testvec2 missing!"
275
+
276
+ tv3l = glGetUniformLocation program, "testvec3"
277
+ refute_equal -1, tv3l, "testvec3 missing!"
278
+
279
+ tv4l = glGetUniformLocation program, "testvec4"
280
+ refute_equal -1, tv4l, "testvec4 missing!"
281
+
282
+ tv1il = glGetUniformLocation program, "testivec1"
283
+ refute_equal -1, tv1il, "testivec1 missing!"
284
+
285
+ tv2il = glGetUniformLocation program, "testivec2"
286
+ refute_equal -1, tv2il, "testivec2 missing!"
287
+
288
+ tv3il = glGetUniformLocation program, "testivec3"
289
+ refute_equal -1, tv3il, "testivec3 missing!"
290
+
291
+ tv4il = glGetUniformLocation program, "testivec4"
292
+ refute_equal -1, tv4il, "testivec4 missing!"
293
+
294
+ assert_equal [1, GL_FLOAT_VEC4, "gl_Vertex"], glGetActiveAttrib(program, 0)
295
+ assert_equal [1, GL_INT, "testivec1"], glGetActiveUniform(program, tv1il)
296
+
297
+ # f
298
+ glUniform1f(tv1l, 2.0)
299
+ assert_equal(glGetUniformfv(program, tv1l), 2.0)
300
+ glUniform2f(tv2l, 2.0, 2.0)
301
+ assert_equal([2.0, 2.0], glGetUniformfv(program, tv2l))
302
+ glUniform3f(tv3l, 2.0, 2.0, 2.0)
303
+ assert_equal([2.0, 2.0, 2.0], glGetUniformfv(program, tv3l))
304
+ glUniform4f(tv4l, 2.0, 2.0, 2.0, 2.0)
305
+ assert_equal([2.0, 2.0, 2.0, 2.0], glGetUniformfv(program, tv4l))
306
+ # i
307
+ glUniform1i(tv1il, 3)
308
+ assert_equal(glGetUniformiv(program, tv1il), 3)
309
+ glUniform2i(tv2il, 3, 3)
310
+ assert_equal([3, 3], glGetUniformiv(program, tv2il))
311
+ glUniform3i(tv3il, 3, 3, 3)
312
+ assert_equal([3, 3, 3], glGetUniformiv(program, tv3il))
313
+ glUniform4i(tv4il, 3, 3, 3, 3)
314
+ assert_equal([3, 3, 3, 3], glGetUniformiv(program, tv4il))
315
+ # fv
316
+ glUniform1fv(tv1l, [3.0])
317
+ assert_equal(glGetUniformfv(program, tv1l), 3.0)
318
+ glUniform2fv(tv2l, [3.0, 3.0])
319
+ assert_equal([3.0, 3.0], glGetUniformfv(program, tv2l))
320
+ glUniform3fv(tv3l, [3.0, 3.0, 3.0])
321
+ assert_equal([3.0, 3.0, 3.0], glGetUniformfv(program, tv3l))
322
+ glUniform4fv(tv4l, [3.0, 3.0, 3.0, 3.0])
323
+ assert_equal([3.0, 3.0, 3.0, 3.0], glGetUniformfv(program, tv4l))
324
+ # iv
325
+ glUniform1iv(tv1il, [2])
326
+ assert_equal(glGetUniformiv(program, tv1il), 2)
327
+ glUniform2iv(tv2il, [2, 2])
328
+ assert_equal([2, 2], glGetUniformiv(program, tv2il))
329
+ glUniform3iv(tv3il, [2, 2, 2])
330
+ assert_equal([2, 2, 2], glGetUniformiv(program, tv3il))
331
+ glUniform4iv(tv4il, [2, 2, 2, 2])
332
+ assert_equal([2, 2, 2, 2], glGetUniformiv(program, tv4il))
333
+
334
+ glDeleteShader(vs)
335
+ glDeleteProgram(program)
336
+ end
337
+
338
+ def test_shaders_3
339
+ vertex_shader_source = <<-SHADER
340
+ #version 110
341
+
342
+ uniform mat2 testmat2;
343
+ uniform mat3 testmat3;
344
+ uniform mat4 testmat4;
345
+
346
+ void main() {
347
+ testmat2;
348
+ testmat3;
349
+ testmat4;
350
+ gl_Position = ftransform();
351
+ }
352
+ SHADER
353
+
354
+ program = glCreateProgram
355
+ vs = glCreateShader GL_VERTEX_SHADER
356
+
357
+ glShaderSource vs, vertex_shader_source
358
+ glCompileShader vs
359
+
360
+ assert glGetShaderiv(vs, GL_COMPILE_STATUS), glGetShaderInfoLog(vs)
361
+
362
+ glAttachShader program, vs
363
+
364
+ glLinkProgram program
365
+ assert glGetProgramiv(program, GL_LINK_STATUS)
366
+
367
+ glValidateProgram program
368
+ assert(glGetProgramiv(program, GL_VALIDATE_STATUS),
369
+ glGetProgramInfoLog(program))
370
+
371
+ glUseProgram program
372
+
373
+ refute_equal(-1, glGetUniformLocation(program, "testmat2"),
374
+ "testmat2 missing!")
375
+ refute_equal(-1, glGetUniformLocation(program, "testmat3"),
376
+ "testmat3 missing!")
377
+ refute_equal(-1, glGetUniformLocation(program, "testmat4"),
378
+ "testmat4 missing!")
379
+
380
+ uniforms = Hash.new do |_, k| raise "invalid uniform #{k}" end
381
+ (0...glGetProgramiv(program, GL_ACTIVE_UNIFORMS)).each do |i|
382
+ uniform = glGetActiveUniform program, i
383
+ uniforms[uniform.last] = i
384
+ end
385
+
386
+ glUniformMatrix2fv(uniforms['testmat2'], GL_TRUE, [0, 1, 1, 0])
387
+
388
+ assert_each_in_delta([0, 1, 1, 0],
389
+ glGetUniformfv(program, uniforms['testmat2']))
390
+
391
+ skip "glUniformMatrix3fv complains but I don't know why"
392
+ glUniformMatrix3fv(uniforms['testmat3'], GL_TRUE,
393
+ [1, 1, 1, 1, 1, 1, 1, 1, 1])
394
+
395
+ assert_each_in_delta([1, 0, 0, 1, 0, 0, 0, 0, 0],
396
+ glGetUniformfv(program, uniforms['testmat3']))
397
+
398
+ glUniformMatrix4fv(uniforms['testmat4'], GL_TRUE,
399
+ [0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0])
400
+
401
+ assert_each_in_delta([0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0],
402
+ glGetUniformfv(program, uniforms['testmat4']))
403
+ ensure
404
+ glDeleteProgram program
405
+ end
406
+
407
+ def test_buffered_vertexattribpointer
408
+ vaa = [1, 1, 1, 1, 2, 2, 2, 2].pack("f*")
409
+
410
+ buffers = glGenBuffers(1)
411
+
412
+ glBindBuffer(GL_ARRAY_BUFFER, buffers[0])
413
+ glBufferData(GL_ARRAY_BUFFER, 8*4, vaa, GL_DYNAMIC_DRAW)
414
+
415
+ glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0)
416
+ assert_equal(glGetVertexAttribPointerv(1), 0)
417
+
418
+ glEnableVertexAttribArray(1)
419
+
420
+ glBegin(GL_POINTS)
421
+ glArrayElement(1)
422
+ glEnd()
423
+ assert_equal([2, 2, 2, 2], glGetVertexAttribfv(1, GL_CURRENT_VERTEX_ATTRIB))
424
+
425
+ glDisableVertexAttribArray(1)
426
+ glDeleteBuffers(buffers)
427
+ end
428
+
429
+ end
430
+