ray 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -6
- data/Rakefile +1 -5
- data/ext/audio.c +25 -19
- data/ext/audio_source.c +67 -39
- data/ext/color.c +19 -19
- data/ext/drawable.c +190 -31
- data/ext/extconf.rb +16 -14
- data/ext/gl.c +310 -30
- data/ext/gl_buffer.c +223 -2
- data/ext/gl_index_buffer.c +11 -0
- data/ext/gl_int_array.c +24 -22
- data/ext/gl_vertex.c +84 -49
- data/ext/image.c +115 -51
- data/ext/image_target.c +58 -10
- data/ext/input.c +73 -6
- data/ext/mo.c +583 -0
- data/ext/mo.h +189 -0
- data/ext/music.c +9 -8
- data/ext/pixel_bus.c +349 -0
- data/ext/polygon.c +68 -45
- data/ext/ray.c +1 -0
- data/ext/ray.h +19 -1
- data/ext/rect.c +9 -47
- data/ext/say.h +1 -2
- data/ext/say_all.h +6 -0
- data/ext/say_audio.h +3 -0
- data/ext/say_audio_context.c +1 -4
- data/ext/say_basic_type.c +24 -0
- data/ext/say_basic_type.h +4 -0
- data/ext/say_buffer.c +217 -88
- data/ext/say_buffer.h +20 -5
- data/ext/say_buffer_renderer.c +10 -7
- data/ext/say_buffer_renderer.h +1 -1
- data/ext/say_buffer_slice.c +70 -76
- data/ext/say_context.c +109 -22
- data/ext/say_context.h +14 -0
- data/ext/say_drawable.c +113 -25
- data/ext/say_drawable.h +23 -2
- data/ext/say_error.c +7 -2
- data/ext/say_font.c +30 -27
- data/ext/say_font.h +3 -6
- data/ext/say_get_proc.c +35 -0
- data/ext/say_image.c +102 -27
- data/ext/say_image.h +11 -4
- data/ext/say_image_target.c +88 -34
- data/ext/say_image_target.h +3 -2
- data/ext/say_index_buffer.c +31 -19
- data/ext/say_index_buffer.h +4 -2
- data/ext/say_index_buffer_slice.c +78 -70
- data/ext/say_music.c +4 -2
- data/ext/say_osx.h +3 -2
- data/ext/say_osx_context.h +37 -4
- data/ext/say_osx_window.h +32 -37
- data/ext/say_pixel_bus.c +163 -0
- data/ext/say_pixel_bus.h +44 -0
- data/ext/say_polygon.c +2 -2
- data/ext/say_shader.c +66 -62
- data/ext/say_shader.h +2 -0
- data/ext/say_sprite.c +1 -2
- data/ext/say_target.c +14 -23
- data/ext/say_target.h +3 -1
- data/ext/say_text.c +45 -7
- data/ext/say_text.h +12 -3
- data/ext/say_thread.c +13 -6
- data/ext/say_thread.h +1 -1
- data/ext/say_thread_variable.c +5 -5
- data/ext/say_vertex_type.c +79 -41
- data/ext/say_vertex_type.h +6 -2
- data/ext/say_view.c +10 -31
- data/ext/say_view.h +1 -5
- data/ext/say_win.h +2 -2
- data/ext/say_win_context.h +49 -11
- data/ext/say_win_window.h +30 -27
- data/ext/say_window.c +3 -3
- data/ext/say_x11.h +3 -1
- data/ext/say_x11_context.h +64 -10
- data/ext/say_x11_window.h +22 -17
- data/ext/shader.c +9 -0
- data/ext/sprite.c +7 -1
- data/ext/target.c +80 -28
- data/ext/text.c +43 -1
- data/ext/view.c +53 -1
- data/ext/window.c +4 -0
- data/lib/ray/animation_list.rb +17 -2
- data/lib/ray/audio_source.rb +11 -0
- data/lib/ray/color.rb +14 -0
- data/lib/ray/drawable.rb +23 -0
- data/lib/ray/dsl/event.rb +1 -9
- data/lib/ray/dsl/event_runner.rb +3 -4
- data/lib/ray/dsl/matcher.rb +20 -1
- data/lib/ray/effect.rb +116 -0
- data/lib/ray/effect/black_and_white.rb +38 -0
- data/lib/ray/effect/color_inversion.rb +16 -0
- data/lib/ray/effect/generator.rb +145 -0
- data/lib/ray/effect/grayscale.rb +32 -0
- data/lib/ray/game.rb +25 -5
- data/lib/ray/gl/vertex.rb +105 -26
- data/lib/ray/helper.rb +5 -0
- data/lib/ray/image.rb +54 -13
- data/lib/ray/image_target.rb +7 -0
- data/lib/ray/matrix.rb +26 -0
- data/lib/ray/music.rb +4 -0
- data/lib/ray/pixel_bus.rb +22 -0
- data/lib/ray/polygon.rb +17 -0
- data/lib/ray/pp.rb +28 -0
- data/lib/ray/ray.rb +7 -1
- data/lib/ray/rect.rb +7 -13
- data/lib/ray/scene.rb +24 -5
- data/lib/ray/scene_list.rb +9 -0
- data/lib/ray/shader.rb +11 -2
- data/lib/ray/sound.rb +4 -0
- data/lib/ray/sprite.rb +23 -62
- data/lib/ray/target.rb +25 -0
- data/lib/ray/text.rb +10 -0
- data/lib/ray/turtle.rb +9 -3
- data/lib/ray/vector.rb +18 -0
- data/lib/ray/vertex.rb +6 -0
- data/lib/ray/view.rb +22 -0
- data/samples/animation/sprite_motion.rb +0 -60
- data/samples/audio/{spacial.rb → spatial.rb} +1 -1
- data/samples/buffer/buffer.rb +1 -0
- data/samples/buffer/index_buffer.rb +2 -0
- data/samples/cptn_ruby/cptn_ruby.rb +6 -7
- data/samples/effects/effect.rb +39 -0
- data/samples/effects/grayscale.rb +27 -0
- data/samples/opengl/image.rb +7 -5
- data/samples/opengl/instancing.rb +159 -0
- data/samples/opengl/instancing.rbc +3231 -0
- data/samples/opengl/obj_loader.rb +9 -8
- data/samples/opengl/shader.rb +1 -3
- data/samples/shaders/geometry.rb +108 -38
- data/samples/shaders/geometry.rbc +2074 -0
- data/samples/shaders/shape.rb +2 -2
- data/samples/starfighter/starfighter.rb +5 -5
- data/samples/window/get_pixel.rb +1 -1
- data/test/animation_list_test.rb +18 -4
- data/test/drawable_test.rb +70 -1
- data/test/effect_generator_test.rb +63 -0
- data/test/effect_test.rb +61 -0
- data/test/game_test.rb +18 -0
- data/test/gl_buffer_test.rb +43 -1
- data/test/gl_index_buffer_test.rb +5 -0
- data/test/gl_vertex_test.rb +28 -1
- data/test/image_test.rb +5 -5
- data/test/input_test.rb +49 -0
- data/test/pixel_bus_test.rb +28 -0
- data/test/rect_test.rb +4 -0
- data/{samples/_media → test/res}/Beep.wav +0 -0
- data/samples/_media/CptnRuby Gem.png b/data/test/res/CptnRuby → Gem.png +0 -0
- data/samples/_media/CptnRuby Map.txt b/data/test/res/CptnRuby → Map.txt +0 -0
- data/samples/_media/CptnRuby Tileset.png b/data/test/res/CptnRuby → Tileset.png +0 -0
- data/{samples/_media → test/res}/CptnRuby.png +0 -0
- data/{samples/_media → test/res}/Space.png +0 -0
- data/{samples/_media → test/res}/Star.png +0 -0
- data/{samples/_media → test/res}/Starfighter.png +0 -0
- data/test/res/cube.obj +28 -0
- data/test/res/light3d.c +2 -2
- data/test/res/stone.png +0 -0
- data/test/scene_test.rb +3 -0
- data/test/sprite_test.rb +10 -0
- data/test/text_test.rb +31 -2
- data/test/view_test.rb +13 -1
- metadata +38 -17
- data/ext/say_array.c +0 -124
- data/ext/say_array.h +0 -34
- data/ext/say_table.c +0 -86
- data/ext/say_table.h +0 -24
data/ext/extconf.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
|
-
$CFLAGS << " -Wextra -Wall -Wno-unused-parameter -std=gnu99
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
50
|
-
|
93
|
+
mo_array *first = ray_rb2int_array(rb_first);
|
94
|
+
mo_array *count = ray_rb2int_array(rb_count);
|
51
95
|
|
52
|
-
|
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
|
-
|
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
|
-
|
75
|
-
|
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 !=
|
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
|
-
|
84
|
-
GL_UNSIGNED_INT, (const GLvoid**)
|
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
|
}
|