opengl 0.9.0-x64-mingw32

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