ray 0.1.1 → 0.2.0

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 (167) hide show
  1. data/README.md +9 -6
  2. data/Rakefile +1 -5
  3. data/ext/audio.c +25 -19
  4. data/ext/audio_source.c +67 -39
  5. data/ext/color.c +19 -19
  6. data/ext/drawable.c +190 -31
  7. data/ext/extconf.rb +16 -14
  8. data/ext/gl.c +310 -30
  9. data/ext/gl_buffer.c +223 -2
  10. data/ext/gl_index_buffer.c +11 -0
  11. data/ext/gl_int_array.c +24 -22
  12. data/ext/gl_vertex.c +84 -49
  13. data/ext/image.c +115 -51
  14. data/ext/image_target.c +58 -10
  15. data/ext/input.c +73 -6
  16. data/ext/mo.c +583 -0
  17. data/ext/mo.h +189 -0
  18. data/ext/music.c +9 -8
  19. data/ext/pixel_bus.c +349 -0
  20. data/ext/polygon.c +68 -45
  21. data/ext/ray.c +1 -0
  22. data/ext/ray.h +19 -1
  23. data/ext/rect.c +9 -47
  24. data/ext/say.h +1 -2
  25. data/ext/say_all.h +6 -0
  26. data/ext/say_audio.h +3 -0
  27. data/ext/say_audio_context.c +1 -4
  28. data/ext/say_basic_type.c +24 -0
  29. data/ext/say_basic_type.h +4 -0
  30. data/ext/say_buffer.c +217 -88
  31. data/ext/say_buffer.h +20 -5
  32. data/ext/say_buffer_renderer.c +10 -7
  33. data/ext/say_buffer_renderer.h +1 -1
  34. data/ext/say_buffer_slice.c +70 -76
  35. data/ext/say_context.c +109 -22
  36. data/ext/say_context.h +14 -0
  37. data/ext/say_drawable.c +113 -25
  38. data/ext/say_drawable.h +23 -2
  39. data/ext/say_error.c +7 -2
  40. data/ext/say_font.c +30 -27
  41. data/ext/say_font.h +3 -6
  42. data/ext/say_get_proc.c +35 -0
  43. data/ext/say_image.c +102 -27
  44. data/ext/say_image.h +11 -4
  45. data/ext/say_image_target.c +88 -34
  46. data/ext/say_image_target.h +3 -2
  47. data/ext/say_index_buffer.c +31 -19
  48. data/ext/say_index_buffer.h +4 -2
  49. data/ext/say_index_buffer_slice.c +78 -70
  50. data/ext/say_music.c +4 -2
  51. data/ext/say_osx.h +3 -2
  52. data/ext/say_osx_context.h +37 -4
  53. data/ext/say_osx_window.h +32 -37
  54. data/ext/say_pixel_bus.c +163 -0
  55. data/ext/say_pixel_bus.h +44 -0
  56. data/ext/say_polygon.c +2 -2
  57. data/ext/say_shader.c +66 -62
  58. data/ext/say_shader.h +2 -0
  59. data/ext/say_sprite.c +1 -2
  60. data/ext/say_target.c +14 -23
  61. data/ext/say_target.h +3 -1
  62. data/ext/say_text.c +45 -7
  63. data/ext/say_text.h +12 -3
  64. data/ext/say_thread.c +13 -6
  65. data/ext/say_thread.h +1 -1
  66. data/ext/say_thread_variable.c +5 -5
  67. data/ext/say_vertex_type.c +79 -41
  68. data/ext/say_vertex_type.h +6 -2
  69. data/ext/say_view.c +10 -31
  70. data/ext/say_view.h +1 -5
  71. data/ext/say_win.h +2 -2
  72. data/ext/say_win_context.h +49 -11
  73. data/ext/say_win_window.h +30 -27
  74. data/ext/say_window.c +3 -3
  75. data/ext/say_x11.h +3 -1
  76. data/ext/say_x11_context.h +64 -10
  77. data/ext/say_x11_window.h +22 -17
  78. data/ext/shader.c +9 -0
  79. data/ext/sprite.c +7 -1
  80. data/ext/target.c +80 -28
  81. data/ext/text.c +43 -1
  82. data/ext/view.c +53 -1
  83. data/ext/window.c +4 -0
  84. data/lib/ray/animation_list.rb +17 -2
  85. data/lib/ray/audio_source.rb +11 -0
  86. data/lib/ray/color.rb +14 -0
  87. data/lib/ray/drawable.rb +23 -0
  88. data/lib/ray/dsl/event.rb +1 -9
  89. data/lib/ray/dsl/event_runner.rb +3 -4
  90. data/lib/ray/dsl/matcher.rb +20 -1
  91. data/lib/ray/effect.rb +116 -0
  92. data/lib/ray/effect/black_and_white.rb +38 -0
  93. data/lib/ray/effect/color_inversion.rb +16 -0
  94. data/lib/ray/effect/generator.rb +145 -0
  95. data/lib/ray/effect/grayscale.rb +32 -0
  96. data/lib/ray/game.rb +25 -5
  97. data/lib/ray/gl/vertex.rb +105 -26
  98. data/lib/ray/helper.rb +5 -0
  99. data/lib/ray/image.rb +54 -13
  100. data/lib/ray/image_target.rb +7 -0
  101. data/lib/ray/matrix.rb +26 -0
  102. data/lib/ray/music.rb +4 -0
  103. data/lib/ray/pixel_bus.rb +22 -0
  104. data/lib/ray/polygon.rb +17 -0
  105. data/lib/ray/pp.rb +28 -0
  106. data/lib/ray/ray.rb +7 -1
  107. data/lib/ray/rect.rb +7 -13
  108. data/lib/ray/scene.rb +24 -5
  109. data/lib/ray/scene_list.rb +9 -0
  110. data/lib/ray/shader.rb +11 -2
  111. data/lib/ray/sound.rb +4 -0
  112. data/lib/ray/sprite.rb +23 -62
  113. data/lib/ray/target.rb +25 -0
  114. data/lib/ray/text.rb +10 -0
  115. data/lib/ray/turtle.rb +9 -3
  116. data/lib/ray/vector.rb +18 -0
  117. data/lib/ray/vertex.rb +6 -0
  118. data/lib/ray/view.rb +22 -0
  119. data/samples/animation/sprite_motion.rb +0 -60
  120. data/samples/audio/{spacial.rb → spatial.rb} +1 -1
  121. data/samples/buffer/buffer.rb +1 -0
  122. data/samples/buffer/index_buffer.rb +2 -0
  123. data/samples/cptn_ruby/cptn_ruby.rb +6 -7
  124. data/samples/effects/effect.rb +39 -0
  125. data/samples/effects/grayscale.rb +27 -0
  126. data/samples/opengl/image.rb +7 -5
  127. data/samples/opengl/instancing.rb +159 -0
  128. data/samples/opengl/instancing.rbc +3231 -0
  129. data/samples/opengl/obj_loader.rb +9 -8
  130. data/samples/opengl/shader.rb +1 -3
  131. data/samples/shaders/geometry.rb +108 -38
  132. data/samples/shaders/geometry.rbc +2074 -0
  133. data/samples/shaders/shape.rb +2 -2
  134. data/samples/starfighter/starfighter.rb +5 -5
  135. data/samples/window/get_pixel.rb +1 -1
  136. data/test/animation_list_test.rb +18 -4
  137. data/test/drawable_test.rb +70 -1
  138. data/test/effect_generator_test.rb +63 -0
  139. data/test/effect_test.rb +61 -0
  140. data/test/game_test.rb +18 -0
  141. data/test/gl_buffer_test.rb +43 -1
  142. data/test/gl_index_buffer_test.rb +5 -0
  143. data/test/gl_vertex_test.rb +28 -1
  144. data/test/image_test.rb +5 -5
  145. data/test/input_test.rb +49 -0
  146. data/test/pixel_bus_test.rb +28 -0
  147. data/test/rect_test.rb +4 -0
  148. data/{samples/_media → test/res}/Beep.wav +0 -0
  149. data/samples/_media/CptnRuby Gem.png b/data/test/res/CptnRuby → Gem.png +0 -0
  150. data/samples/_media/CptnRuby Map.txt b/data/test/res/CptnRuby → Map.txt +0 -0
  151. data/samples/_media/CptnRuby Tileset.png b/data/test/res/CptnRuby → Tileset.png +0 -0
  152. data/{samples/_media → test/res}/CptnRuby.png +0 -0
  153. data/{samples/_media → test/res}/Space.png +0 -0
  154. data/{samples/_media → test/res}/Star.png +0 -0
  155. data/{samples/_media → test/res}/Starfighter.png +0 -0
  156. data/test/res/cube.obj +28 -0
  157. data/test/res/light3d.c +2 -2
  158. data/test/res/stone.png +0 -0
  159. data/test/scene_test.rb +3 -0
  160. data/test/sprite_test.rb +10 -0
  161. data/test/text_test.rb +31 -2
  162. data/test/view_test.rb +13 -1
  163. metadata +38 -17
  164. data/ext/say_array.c +0 -124
  165. data/ext/say_array.h +0 -34
  166. data/ext/say_table.c +0 -86
  167. data/ext/say_table.h +0 -24
@@ -1,6 +1,6 @@
1
1
  require 'mkmf'
2
2
 
3
- $CFLAGS << " -Wextra -Wall -Wno-unused-parameter -std=gnu99 -g -O0"
3
+ $CFLAGS << " -Wextra -Wall -Wno-unused-parameter -std=gnu99"
4
4
 
5
5
  unless RUBY_PLATFORM =~ /mingw/
6
6
  $CFLAGS << " " << `freetype-config --cflags`.chomp
@@ -21,59 +21,61 @@ elsif RUBY_PLATFORM =~ /mingw/
21
21
  def vendor_path(file)
22
22
  File.join(File.dirname(__FILE__), "vendor", file)
23
23
  end
24
-
24
+
25
25
  def vendor(file)
26
26
  '"' + vendor_path(file) + '"'
27
27
  end
28
-
28
+
29
29
  def rel(file)
30
30
  File.join(File.dirname(__FILE__), file)
31
31
  end
32
-
32
+
33
33
  require 'fileutils'
34
34
  include FileUtils
35
-
35
+
36
36
  cp vendor_path("openal/Win32/soft_oal.dll"), rel("OpenAL32.dll")
37
37
  cp vendor_path("freetype/bin/freetype6.dll"), rel("freetype6.dll")
38
38
  cp vendor_path("freetype/bin/zlib1.dll"), rel("zlib1.dll")
39
39
  cp vendor_path("glew/lib/glew32.dll"), rel("glew32.dll")
40
40
  cp vendor_path("sndfile/bin/libsndfile-1.dll"), rel("libsndfile-1.dll")
41
-
41
+
42
42
  $CFLAGS << " -DSAY_WIN"
43
43
 
44
44
  # Windows API
45
45
  have_library "gdi32"
46
-
46
+
47
47
  # OpenGL and GLEW
48
48
  $CFLAGS << " -I#{vendor("glew/include")}"
49
49
  $LDFLAGS << " -L#{vendor("glew/lib")}"
50
-
50
+
51
51
  have_library "opengl32"
52
52
  have_library "glew32"
53
-
53
+
54
54
  # Freetype
55
55
  $CFLAGS << " -I#{vendor("freetype/include")}"
56
56
  $CFLAGS << " -I#{vendor("freetype/include/freetype2")}"
57
57
  $LDFLAGS << " -L#{vendor("freetype/lib")}"
58
-
58
+
59
59
  have_library "libfreetype"
60
-
60
+
61
61
  # OpenAL
62
62
  $CFLAGS << " -I#{vendor("openal/include")}"
63
63
  $LDFLAGS << " -L#{vendor("openal/lib")}"
64
-
64
+
65
65
  have_library "OpenAL32"
66
-
66
+
67
67
  # libsndfile
68
68
  $CFLAGS << " -I#{vendor("sndfile/include")}"
69
69
  $LDFLAGS << " -L#{vendor("sndfile/lib")}"
70
-
70
+
71
71
  have_library "libsndfile-1"
72
72
 
73
73
  create_makefile 'ray_ext'
74
74
  else
75
75
  $CFLAGS << " -DSAY_X11"
76
76
 
77
+ have_header "GL/glxext.h"
78
+
77
79
  have_header "X11/extensions/Xrandr.h"
78
80
  have_library "Xrandr"
79
81
 
data/ext/gl.c CHANGED
@@ -4,19 +4,17 @@ VALUE ray_mGL = Qnil;
4
4
  static VALUE ray_gl_primitives = Qnil;
5
5
 
6
6
  /*
7
- @overload draw_arrays(primitive, first, count)
8
- @note Misusing this method can cause a crash.
9
- @param [Symbol] primitive Primitive to draw. Must be one of the folowing:
10
- points, line_strip, line_loop, lines, triangle_strip, triangle_fan,
11
- triangles.
12
-
13
- @param [Integer] first Identifier of the first vertex to draw.
14
- @param [Integer] count Amount of vertices to draw.
15
- */
7
+ * @overload draw_arrays(primitive, first, count)
8
+ * @param [Symbol] primitive Primitive to draw. Must be one of the folowing:
9
+ * points, line_strip, line_loop, lines, triangle_strip, triangle_fan,
10
+ * triangles.
11
+ *
12
+ * @param [Integer] first Identifier of the first vertex to draw.
13
+ * @param [Integer] count Amount of vertices to draw.
14
+ */
16
15
  static
17
16
  VALUE ray_gl_draw_arrays(VALUE self, VALUE primitive, VALUE first,
18
17
  VALUE count) {
19
-
20
18
  glDrawArrays(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
21
19
  NUM2ULONG(first), NUM2ULONG(count));
22
20
  return Qnil;
@@ -38,25 +36,69 @@ VALUE ray_gl_draw_elements(VALUE self, VALUE primitive, VALUE count,
38
36
  }
39
37
 
40
38
  /*
41
- @overload multi_draw_arrays(primitive, first, count)
42
- @param primitive (see #draw_arrays)
43
- @param [Ray::GL::IntArray] first Indices of the first vertex
44
- @param [Ray::GL::IntArray] count Ammount of vertices to draw
45
- */
39
+ * @overload draw_arrays_instanced(primitive, first, count, instance_count)
40
+ * @param [Symbol] primitive (see #draw_arrays)
41
+ * @param [Integer] first (see #draw_arrays)
42
+ * @param [Integer] count (see #draw_arrays)
43
+ * @param [Integer] instance_count Amount of instances to draw
44
+ */
45
+ static
46
+ VALUE ray_gl_draw_arrays_instanced(VALUE self, VALUE primitive, VALUE first,
47
+ VALUE count, VALUE instance_count) {
48
+ say_context_ensure();
49
+ if (glDrawArraysInstanced) {
50
+ glDrawArraysInstanced(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
51
+ NUM2ULONG(first), NUM2ULONG(count),
52
+ NUM2ULONG(instance_count));
53
+ }
54
+ else
55
+ rb_raise(rb_eRuntimeError, "GL_ARB_draw_instanced is not supported");
56
+
57
+ return Qnil;
58
+ }
59
+
60
+ /*
61
+ * @overload draw_elements_instanced(primitive, count, index, instance_count)
62
+ * @param primitive (see #draw_arrays)
63
+ * @param count (see #draw_arrays)
64
+ * @param index (see #draw_elements)
65
+ * @param instance_count (see #draw_arrays_instanced)
66
+ */
67
+ static
68
+ VALUE ray_gl_draw_elements_instanced(VALUE self, VALUE primitive, VALUE count,
69
+ VALUE index, VALUE instance_count) {
70
+ say_context_ensure();
71
+ if (glDrawElementsInstanced) {
72
+ glDrawElementsInstanced(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
73
+ NUM2ULONG(count),
74
+ GL_UNSIGNED_INT, (void*)NUM2ULONG(index),
75
+ NUM2ULONG(instance_count));
76
+ }
77
+ else
78
+ rb_raise(rb_eRuntimeError, "GL_ARB_draw_instanced is not supported");
79
+
80
+ return Qnil;
81
+ }
82
+
83
+
84
+ /*
85
+ * @overload multi_draw_arrays(primitive, first, count)
86
+ * @param primitive (see #draw_arrays)
87
+ * @param [Ray::GL::IntArray] first Indices of the first vertex
88
+ * @param [Ray::GL::IntArray] count Ammount of vertices to draw
89
+ */
46
90
  static
47
91
  VALUE ray_gl_multi_draw_arrays(VALUE self, VALUE primitive, VALUE rb_first,
48
92
  VALUE rb_count) {
49
- say_array *first = ray_rb2int_array(rb_first);
50
- say_array *count = ray_rb2int_array(rb_count);
93
+ mo_array *first = ray_rb2int_array(rb_first);
94
+ mo_array *count = ray_rb2int_array(rb_count);
51
95
 
52
- size_t size = say_array_get_size(first);
53
-
54
- if (size != say_array_get_size(count))
96
+ if (first->size != count->size)
55
97
  rb_raise(rb_eArgError, "first and count arrays should have the same size");
56
98
 
57
99
  glMultiDrawArrays(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
58
- say_array_get(first, 0), say_array_get(count, 0),
59
- size);
100
+ mo_array_at(first, 0), mo_array_at(count, 0),
101
+ first->size);
60
102
 
61
103
  return Qnil;
62
104
  }
@@ -71,21 +113,221 @@ VALUE ray_gl_multi_draw_arrays(VALUE self, VALUE primitive, VALUE rb_first,
71
113
  static
72
114
  VALUE ray_gl_multi_draw_elements(VALUE self, VALUE primitive, VALUE rb_count,
73
115
  VALUE rb_index) {
74
- say_array *index = ray_rb2int_array(rb_index);
75
- say_array *count = ray_rb2int_array(rb_count);
76
-
77
- size_t size = say_array_get_size(index);
116
+ mo_array *index = ray_rb2int_array(rb_index);
117
+ mo_array *count = ray_rb2int_array(rb_count);
78
118
 
79
- if (size != say_array_get_size(count))
119
+ if (index->size != count->size)
80
120
  rb_raise(rb_eArgError, "index and count arrays should have the same size");
81
121
 
82
122
  glMultiDrawElements(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
83
- say_array_get(count, 0),
84
- GL_UNSIGNED_INT, (const GLvoid**)say_array_get(count, 0),
85
- size);
123
+ mo_array_at(count, 0),
124
+ GL_UNSIGNED_INT, (const GLvoid**)mo_array_at(index, 0),
125
+ index->size);
86
126
  return Qnil;
87
127
  }
88
128
 
129
+ /* @return [Integer] Size of the depth buffer, in bits */
130
+ static
131
+ VALUE ray_gl_depth_size(VALUE self) {
132
+ return ULONG2NUM(say_context_get_config()->depth_size);
133
+ }
134
+
135
+ /* @return [Integer] Size of the stencil buffer, in bits */
136
+ static
137
+ VALUE ray_gl_stencil_size(VALUE self) {
138
+ return ULONG2NUM(say_context_get_config()->stencil_size);
139
+ }
140
+
141
+ /* @return [Integer] Major version number. Ignored if less than 3. */
142
+ static
143
+ VALUE ray_gl_major_version(VALUE self) {
144
+ return ULONG2NUM(say_context_get_config()->major_version);
145
+ }
146
+
147
+ /* @return [Integer] Minor version number */
148
+ static
149
+ VALUE ray_gl_minor_version(VALUE self) {
150
+ return ULONG2NUM(say_context_get_config()->minor_version);
151
+ }
152
+
153
+ /* @return [Bollean] True when a core OpenGL profile must be used */
154
+ static
155
+ VALUE ray_gl_core_profile(VALUE self) {
156
+ return say_context_get_config()->core_profile ? Qtrue : Qfalse;
157
+ }
158
+
159
+ /* @see depth_size */
160
+ static
161
+ VALUE ray_gl_set_depth_size(VALUE self, VALUE val) {
162
+ say_context_get_config()->depth_size = NUM2ULONG(val);
163
+ return val;
164
+ }
165
+
166
+ /* @see stencil_size */
167
+ static
168
+ VALUE ray_gl_set_stencil_size(VALUE self, VALUE val) {
169
+ say_context_get_config()->stencil_size = NUM2ULONG(val);
170
+ return val;
171
+ }
172
+
173
+ /* @see major_version */
174
+ static
175
+ VALUE ray_gl_set_major_version(VALUE self, VALUE val) {
176
+ say_context_get_config()->major_version = NUM2ULONG(val);
177
+ return val;
178
+ }
179
+
180
+ /* @see minor_version */
181
+ static
182
+ VALUE ray_gl_set_minor_version(VALUE self, VALUE val) {
183
+ say_context_get_config()->minor_version = NUM2ULONG(val);
184
+ return val;
185
+ }
186
+
187
+ /* @see core_profile? */
188
+ static
189
+ VALUE ray_gl_set_core_profile(VALUE self, VALUE val) {
190
+ say_context_get_config()->core_profile = RTEST(val);
191
+ return val;
192
+ }
193
+
194
+ /* @return [true, false] True if debugging mode is enabled */
195
+ static
196
+ VALUE ray_gl_debug(VALUE self) {
197
+ return say_context_get_config()->debug ? Qtrue : Qfalse;
198
+ }
199
+
200
+ /* @see debug? */
201
+ static
202
+ VALUE ray_gl_set_debug(VALUE self, VALUE val) {
203
+ say_context_get_config()->debug = RTEST(val);
204
+ return val;
205
+ }
206
+
207
+ static
208
+ void ray_gl_debug_proc(GLenum source,
209
+ GLenum type,
210
+ GLuint id,
211
+ GLenum severity,
212
+ GLsizei length,
213
+ const GLchar *message,
214
+ GLvoid *param) {
215
+ VALUE rb_source = Qnil;
216
+ switch (source) {
217
+ case GL_DEBUG_SOURCE_API_ARB:
218
+ rb_source = RAY_SYM("api"); break;
219
+ case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB:
220
+ rb_source = RAY_SYM("window_system"); break;
221
+ case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB:
222
+ rb_source = RAY_SYM("shader_compiler"); break;
223
+ case GL_DEBUG_SOURCE_THIRD_PARTY_ARB:
224
+ rb_source = RAY_SYM("third_party"); break;
225
+ case GL_DEBUG_SOURCE_APPLICATION_ARB:
226
+ rb_source = RAY_SYM("application"); break;
227
+ default:
228
+ rb_source = RAY_SYM("other"); break;
229
+ }
230
+
231
+ VALUE rb_type = Qnil;
232
+ switch (type) {
233
+ case GL_DEBUG_TYPE_ERROR_ARB:
234
+ rb_type = RAY_SYM("error"); break;
235
+ case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB:
236
+ rb_type = RAY_SYM("deprecated_behavior"); break;
237
+ case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB:
238
+ rb_type = RAY_SYM("undefined_behavior"); break;
239
+ case GL_DEBUG_TYPE_PORTABILITY_ARB:
240
+ rb_type = RAY_SYM("portability"); break;
241
+ case GL_DEBUG_TYPE_PERFORMANCE_ARB:
242
+ rb_type = RAY_SYM("performance"); break;
243
+ default:
244
+ rb_type = RAY_SYM("other"); break;
245
+ }
246
+
247
+ VALUE rb_id = ULONG2NUM(id);
248
+
249
+ VALUE rb_severity = Qnil;
250
+ switch (severity) {
251
+ case GL_DEBUG_SEVERITY_HIGH_ARB:
252
+ rb_severity = RAY_SYM("high"); break;
253
+ case GL_DEBUG_SEVERITY_MEDIUM_ARB:
254
+ rb_severity = RAY_SYM("medium"); break;
255
+ default:
256
+ rb_severity = RAY_SYM("low"); break;
257
+ }
258
+
259
+ VALUE rb_message = rb_str_new(message, length);
260
+
261
+ VALUE proc = rb_iv_get(rb_path2class("Ray::GL"), "@callback");
262
+ rb_funcall(proc, RAY_METH("call"), 5, rb_source, rb_type, rb_id, rb_severity,
263
+ rb_message);
264
+ }
265
+
266
+ /* @return [True, False] True if a callback proc can be set */
267
+ static
268
+ VALUE ray_gl_has_callback(VALUE self) {
269
+ say_context_ensure();
270
+ return glDebugMessageCallbackARB ? Qtrue : Qfalse;
271
+ }
272
+
273
+ /*
274
+ * @overload callback=(proc)
275
+ * Sets the proc called by OpenGL for debugging purpose
276
+ * @param [Proc, nil] proc A proc, or nil to disable debugging
277
+ *
278
+ * The given proc will be called upon some events (errors or warnings about
279
+ * performance and undifined behaviors) with the following arguments:
280
+ *
281
+ * 1. A source (:api, :window_system, :shader_compiler, :third_party,
282
+ * :application, :other).
283
+ * 2. A type (:error, :depreacted_behavior, :undefined_behavior, :portability,
284
+ * :performance, :other).
285
+ * 3. An integer identifier.
286
+ * 4. A severity (:high, :medium, :low).
287
+ * 5. A human-readable message.
288
+ *
289
+ * Notice the debugging proc is only called if the context has been created
290
+ * in debug mode.
291
+ *
292
+ * @example
293
+ * Ray::GL.debug = true # required
294
+ *
295
+ * Ray::GL.callback = proc do |source, type, _, severity, msg|
296
+ * puts "[#{source}][#{type}][#{severity}] #{msg}"
297
+ * end
298
+ *
299
+ * @see debug?
300
+ */
301
+ static
302
+ VALUE ray_gl_set_callback(VALUE self, VALUE proc) {
303
+ say_context_ensure();
304
+
305
+ if (!glDebugMessageCallbackARB)
306
+ rb_raise(rb_eRuntimeError, "setting the debug proc isn't supported");
307
+
308
+ rb_iv_set(rb_path2class("Ray::GL"), "@callback", proc);
309
+ if (RTEST(proc))
310
+ glDebugMessageCallbackARB(ray_gl_debug_proc, NULL);
311
+ else
312
+ glDebugMessageCallbackARB(NULL, NULL);
313
+
314
+ return proc;
315
+ }
316
+
317
+ /*
318
+ * Ensures an OpenGL context is active for the current thread
319
+ */
320
+ static
321
+ VALUE ray_gl_ensure_context(VALUE self) {
322
+ say_context_ensure();
323
+ return Qnil;
324
+ }
325
+
326
+ /*
327
+ * Document-Class: Ray::GL
328
+ *
329
+ * The GL module is used to give access to low-level OpenGL features in Ray.
330
+ */
89
331
  void Init_ray_gl() {
90
332
  ray_mGL = rb_define_module_under(ray_mRay, "GL");
91
333
 
@@ -104,11 +346,49 @@ void Init_ray_gl() {
104
346
  /* @return [Hash] Available primitives. */
105
347
  rb_define_const(ray_mGL, "Primitives", ray_gl_primitives);
106
348
 
349
+ /* @group Context configuration */
350
+ rb_define_module_function(ray_mGL, "depth_size", ray_gl_depth_size, 0);
351
+ rb_define_module_function(ray_mGL, "depth_size=", ray_gl_set_depth_size, 1);
352
+
353
+ rb_define_module_function(ray_mGL, "stencil_size", ray_gl_stencil_size, 0);
354
+ rb_define_module_function(ray_mGL, "stencil_size=", ray_gl_set_stencil_size,
355
+ 1);
356
+
357
+ rb_define_module_function(ray_mGL, "major_version", ray_gl_major_version, 0);
358
+ rb_define_module_function(ray_mGL, "major_version=", ray_gl_set_major_version,
359
+ 1);
360
+
361
+ rb_define_module_function(ray_mGL, "minor_version", ray_gl_minor_version, 0);
362
+ rb_define_module_function(ray_mGL, "minor_version=", ray_gl_set_minor_version,
363
+ 1);
364
+
365
+ rb_define_module_function(ray_mGL, "core_profile?", ray_gl_core_profile, 0);
366
+ rb_define_module_function(ray_mGL, "core_profile=", ray_gl_set_core_profile,
367
+ 1);
368
+
369
+ rb_define_module_function(ray_mGL, "debug?", ray_gl_debug, 0);
370
+ rb_define_module_function(ray_mGL, "debug=", ray_gl_set_debug, 1);
371
+ /* @endgroup */
372
+
373
+
374
+ /* @group Low-level rendering */
107
375
  rb_define_module_function(ray_mGL, "draw_arrays", ray_gl_draw_arrays, 3);
108
376
  rb_define_module_function(ray_mGL, "draw_elements", ray_gl_draw_elements, 3);
109
377
 
378
+ rb_define_module_function(ray_mGL, "draw_arrays_instanced",
379
+ ray_gl_draw_arrays_instanced, 4);
380
+ rb_define_module_function(ray_mGL, "draw_elements_instanced",
381
+ ray_gl_draw_elements_instanced, 4);
382
+
110
383
  rb_define_module_function(ray_mGL, "multi_draw_arrays",
111
384
  ray_gl_multi_draw_arrays, 3);
112
385
  rb_define_module_function(ray_mGL, "multi_draw_elements",
113
386
  ray_gl_multi_draw_elements, 3);
387
+ /* @endgroup */
388
+
389
+ rb_define_module_function(ray_mGL, "has_callback?", ray_gl_has_callback, 0);
390
+ rb_define_module_function(ray_mGL, "callback=", ray_gl_set_callback, 1);
391
+
392
+ rb_define_module_function(ray_mGL, "ensure_context", ray_gl_ensure_context,
393
+ 0);
114
394
  }