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/polygon.c
CHANGED
@@ -17,12 +17,18 @@ say_polygon *ray_rb2polygon(VALUE obj) {
|
|
17
17
|
static
|
18
18
|
VALUE ray_polygon_alloc(VALUE self) {
|
19
19
|
say_polygon *obj = say_polygon_create(0);
|
20
|
-
|
20
|
+
VALUE rb = Data_Wrap_Struct(self, NULL, say_polygon_free, obj);
|
21
|
+
|
22
|
+
say_drawable_set_shader_proc(obj->drawable, ray_drawable_shader_proc);
|
23
|
+
say_drawable_set_other_data(obj->drawable, (void*)rb);
|
24
|
+
|
25
|
+
return rb;
|
21
26
|
}
|
22
27
|
|
23
28
|
static
|
24
29
|
VALUE ray_polygon_init_copy(VALUE self, VALUE other) {
|
25
30
|
say_polygon_copy(ray_rb2polygon(self), ray_rb2polygon(other));
|
31
|
+
ray_drawable_copy_attr(self, other);
|
26
32
|
return self;
|
27
33
|
}
|
28
34
|
|
@@ -41,16 +47,16 @@ void ray_polygon_make_outline(say_polygon *poly, VALUE outline_width,
|
|
41
47
|
}
|
42
48
|
|
43
49
|
/*
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
*/
|
50
|
+
* @overload line(first, last, width = 1, color = Ray::Color.white)
|
51
|
+
* @param [Vector2, #to_vector2] first First point of the line
|
52
|
+
* @param [Vector2, #to_vector2] last Last point of the line
|
53
|
+
*
|
54
|
+
* @param [Float] width Width of the line
|
55
|
+
*
|
56
|
+
* @param [Ray::Color] color Color of the line
|
57
|
+
*
|
58
|
+
* @return [Ray::Polygon] A line
|
59
|
+
*/
|
54
60
|
static
|
55
61
|
VALUE ray_polygon_line(int argc, VALUE *argv, VALUE self) {
|
56
62
|
VALUE first = Qnil, last = Qnil, width = Qnil, color = Qnil;
|
@@ -62,19 +68,24 @@ VALUE ray_polygon_line(int argc, VALUE *argv, VALUE self) {
|
|
62
68
|
NIL_P(color) ?
|
63
69
|
say_make_color(255, 255, 255, 255) :
|
64
70
|
ray_rb2col(color));
|
65
|
-
|
71
|
+
VALUE rb = Data_Wrap_Struct(self, NULL, say_polygon_free, line);
|
72
|
+
|
73
|
+
say_drawable_set_shader_proc(line->drawable, ray_drawable_shader_proc);
|
74
|
+
say_drawable_set_other_data(line->drawable, (void*)rb);
|
75
|
+
|
76
|
+
return rb;
|
66
77
|
}
|
67
78
|
|
68
79
|
/*
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
*/
|
80
|
+
* @overload rectangle(rect, color = Ray::Color.white, outline_width = 0,
|
81
|
+
* outline_color = Ray::Color.white)
|
82
|
+
* @param [Ray::Rect, #to_rect] rect Rectangle occupied by the polygon
|
83
|
+
* @param [Ray::Color] color Color of the rectangle
|
84
|
+
* @param [Float] outline_width Width of the outline
|
85
|
+
* @param [Ray::Color] outline_color Color of the outline
|
86
|
+
*
|
87
|
+
* @return [Ray::Polygon] A rectangle
|
88
|
+
*/
|
78
89
|
static
|
79
90
|
VALUE ray_polygon_rectangle(int argc, VALUE *argv, VALUE self) {
|
80
91
|
VALUE rb_rect = Qnil, rb_color = Qnil, outline_width = Qnil, outline = Qnil;
|
@@ -91,21 +102,25 @@ VALUE ray_polygon_rectangle(int argc, VALUE *argv, VALUE self) {
|
|
91
102
|
|
92
103
|
ray_polygon_make_outline(poly, outline_width, outline);
|
93
104
|
|
105
|
+
say_drawable_set_shader_proc(poly->drawable, ray_drawable_shader_proc);
|
106
|
+
say_drawable_set_other_data(poly->drawable, (void*)ret);
|
107
|
+
|
94
108
|
return ret;
|
95
109
|
}
|
96
110
|
|
97
111
|
/*
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
112
|
+
* @overload circle(center, radius, color = Ray::Color.white, outline_width = 0,
|
113
|
+
* outline_color = Ray::Color.white)
|
114
|
+
*
|
115
|
+
* @param [Ray::Vector2] center The center of the circle
|
116
|
+
* @param [Float] radius The radius of the circle
|
117
|
+
* @param [Ray::Color] color The color of the circle
|
118
|
+
*
|
119
|
+
* @param outline_width (see rectangle)
|
120
|
+
* @param outline_color (see rectangle)
|
121
|
+
*
|
122
|
+
* @return [Ray::Polygon] A circle
|
123
|
+
*/
|
109
124
|
static
|
110
125
|
VALUE ray_polygon_circle(int argc, VALUE *argv, VALUE self) {
|
111
126
|
VALUE rb_center = Qnil, rb_radius = Qnil, rb_color = Qnil,
|
@@ -124,22 +139,25 @@ VALUE ray_polygon_circle(int argc, VALUE *argv, VALUE self) {
|
|
124
139
|
|
125
140
|
ray_polygon_make_outline(poly, rb_outline_width, rb_outline);
|
126
141
|
|
142
|
+
say_drawable_set_shader_proc(poly->drawable, ray_drawable_shader_proc);
|
143
|
+
say_drawable_set_other_data(poly->drawable, (void*)ret);
|
144
|
+
|
127
145
|
return ret;
|
128
146
|
}
|
129
147
|
|
130
148
|
/*
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
*/
|
149
|
+
* @overload ellipse(center, rx, ry, color = Ray::Color.white,
|
150
|
+
* outline_width = 0, outline_color = Ray::Color.white)
|
151
|
+
*
|
152
|
+
* @param [Ray::Vector2] center The center of the ellipse
|
153
|
+
* @param [Float] rx Horizontal radius
|
154
|
+
* @param [Float] ry Vertical radius
|
155
|
+
* @param [Ray::Color] color The color of the ellipse
|
156
|
+
* @param outline_width (see rectangle)
|
157
|
+
* @param outline_color (see rectangle)
|
158
|
+
*
|
159
|
+
* @return [Ray::Polygon] An ellipse
|
160
|
+
*/
|
143
161
|
static
|
144
162
|
VALUE ray_polygon_ellipse(int argc, VALUE *argv, VALUE self) {
|
145
163
|
VALUE rb_center = Qnil, rb_rx = Qnil, rb_ry = Qnil, rb_color = Qnil,
|
@@ -157,7 +175,12 @@ VALUE ray_polygon_ellipse(int argc, VALUE *argv, VALUE self) {
|
|
157
175
|
|
158
176
|
ray_polygon_make_outline(poly, rb_outline_width, rb_outline);
|
159
177
|
|
160
|
-
|
178
|
+
VALUE rb = Data_Wrap_Struct(self, NULL, say_polygon_free, poly);
|
179
|
+
|
180
|
+
say_drawable_set_shader_proc(poly->drawable, ray_drawable_shader_proc);
|
181
|
+
say_drawable_set_other_data(poly->drawable, (void*)rb);
|
182
|
+
|
183
|
+
return rb;
|
161
184
|
}
|
162
185
|
|
163
186
|
/*
|
data/ext/ray.c
CHANGED
data/ext/ray.h
CHANGED
@@ -29,9 +29,11 @@ extern VALUE ray_cColor;
|
|
29
29
|
extern VALUE ray_cVertex;
|
30
30
|
extern VALUE ray_mGL;
|
31
31
|
extern VALUE ray_cGLVertex;
|
32
|
+
extern VALUE ray_cGLInstance;
|
32
33
|
extern VALUE ray_cIntArray;
|
33
34
|
extern VALUE ray_cGLBuffer;
|
34
35
|
extern VALUE ray_cGLIndexBuffer;
|
36
|
+
extern VALUE ray_cPixelBus;
|
35
37
|
extern VALUE ray_cImage;
|
36
38
|
extern VALUE ray_cFont;
|
37
39
|
extern VALUE ray_cShader;
|
@@ -63,6 +65,18 @@ extern VALUE ray_cMusic;
|
|
63
65
|
|
64
66
|
#define RAY_ARRAY_AT(ary, i) (rb_funcall(ary, RAY_METH("[]"), 1, INT2FIX(i)))
|
65
67
|
|
68
|
+
#if defined(JRUBY) && defined(_DARWIN_C_SOURCE)
|
69
|
+
# include <dispatch/dispatch.h>
|
70
|
+
|
71
|
+
# define RAY_MAIN dispatch_sync(dispatch_get_main_queue(), ^
|
72
|
+
# define RAY_MAIN_END );
|
73
|
+
# define RAY_BLOCK __block
|
74
|
+
#else
|
75
|
+
# define RAY_MAIN if (1)
|
76
|
+
# define RAY_MAIN_END
|
77
|
+
# define RAY_BLOCK
|
78
|
+
#endif
|
79
|
+
|
66
80
|
void Init_ray_ext();
|
67
81
|
void Init_ray_vector();
|
68
82
|
void Init_ray_rect();
|
@@ -74,6 +88,7 @@ void Init_ray_gl_vertex();
|
|
74
88
|
void Init_ray_int_array();
|
75
89
|
void Init_ray_gl_buffer();
|
76
90
|
void Init_ray_gl_index_buffer();
|
91
|
+
void Init_ray_pixel_bus();
|
77
92
|
void Init_ray_image();
|
78
93
|
void Init_ray_font();
|
79
94
|
void Init_ray_shader();
|
@@ -128,6 +143,9 @@ say_font *ray_rb2font(VALUE obj);
|
|
128
143
|
VALUE ray_shader2rb(say_shader *shader, VALUE owner);
|
129
144
|
say_shader *ray_rb2shader(VALUE obj);
|
130
145
|
|
146
|
+
void ray_drawable_copy_attr(VALUE self, VALUE orig);
|
147
|
+
void ray_drawable_shader_proc(void *data, say_shader *shader);
|
148
|
+
|
131
149
|
say_drawable *ray_rb2drawable(VALUE obj);
|
132
150
|
say_polygon *ray_rb2polygon(VALUE obj);
|
133
151
|
say_sprite *ray_rb2sprite(VALUE obj);
|
@@ -148,7 +166,7 @@ say_audio_source *ray_rb2audio_source(VALUE obj);
|
|
148
166
|
say_sound *ray_rb2sound(VALUE obj);
|
149
167
|
say_music *ray_rb2music(VALUE obj);
|
150
168
|
|
151
|
-
|
169
|
+
mo_array *ray_rb2int_array(VALUE obj);
|
152
170
|
|
153
171
|
say_buffer_renderer *ray_rb2buf_renderer(VALUE obj);
|
154
172
|
|
data/ext/rect.c
CHANGED
@@ -39,59 +39,21 @@ VALUE ray_alloc_rect(VALUE self) {
|
|
39
39
|
}
|
40
40
|
|
41
41
|
/*
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@overload initialize(hash)
|
49
|
-
Creates a new rect according to the keys specified in hash.
|
50
|
-
|
51
|
-
@option hash [Float] :x
|
52
|
-
@option hash [Float] :y
|
53
|
-
@option hash [Float] (0) :width
|
54
|
-
@option hash [Float] (0) :height required if width is set
|
55
|
-
|
56
|
-
@option hash [Float] (0) :w alias for :width
|
57
|
-
@option hash [Float] (0) :h alias for :height
|
58
|
-
*/
|
42
|
+
* @overload initialize(x, y)
|
43
|
+
* Creates a new rect with size set to (0, 0).
|
44
|
+
*
|
45
|
+
* @overload initialize(x, y, w, h)
|
46
|
+
* Creates a new rect with the specified size.
|
47
|
+
*/
|
59
48
|
static
|
60
49
|
VALUE ray_init_rect(int argc, VALUE *argv, VALUE self) {
|
61
|
-
VALUE
|
62
|
-
rb_scan_args(argc, argv, "
|
63
|
-
|
64
|
-
int type = TYPE(x_or_hash);
|
65
|
-
if (type == T_HASH) {
|
66
|
-
if (!NIL_P(y)) {
|
67
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
|
68
|
-
argc);
|
69
|
-
}
|
70
|
-
|
71
|
-
VALUE hash = x_or_hash;
|
72
|
-
|
73
|
-
x_or_hash = rb_hash_aref(hash, RAY_SYM("x"));
|
74
|
-
y = rb_hash_aref(hash, RAY_SYM("y"));
|
75
|
-
|
76
|
-
w = rb_hash_aref(hash, RAY_SYM("width"));
|
77
|
-
h = rb_hash_aref(hash, RAY_SYM("height"));
|
78
|
-
|
79
|
-
if (NIL_P(w)) w = rb_hash_aref(hash, RAY_SYM("w"));
|
80
|
-
if (NIL_P(h)) h = rb_hash_aref(hash, RAY_SYM("h"));
|
81
|
-
|
82
|
-
if (NIL_P(y)) {
|
83
|
-
rb_raise(rb_eArgError, "missing option :y");
|
84
|
-
}
|
85
|
-
|
86
|
-
if (!NIL_P(w) && NIL_P(h)) {
|
87
|
-
rb_raise(rb_eArgError, "missing option :height");
|
88
|
-
}
|
89
|
-
}
|
50
|
+
VALUE x, y, w, h;
|
51
|
+
rb_scan_args(argc, argv, "22", &x, &y, &w, &h);
|
90
52
|
|
91
53
|
say_rect *rect;
|
92
54
|
Data_Get_Struct(self, say_rect, rect);
|
93
55
|
|
94
|
-
rect->x = NUM2DBL(
|
56
|
+
rect->x = NUM2DBL(x);
|
95
57
|
rect->y = NUM2DBL(y);
|
96
58
|
|
97
59
|
if (!NIL_P(w)) {
|
data/ext/say.h
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
#define SAY_H_
|
3
3
|
|
4
4
|
#include "say_basic_type.h"
|
5
|
-
#include "say_array.h"
|
6
|
-
#include "say_table.h"
|
7
5
|
#include "say_thread.h"
|
8
6
|
#include "say_matrix.h"
|
9
7
|
#include "say_image.h"
|
@@ -14,6 +12,7 @@
|
|
14
12
|
#include "say_buffer_slice.h"
|
15
13
|
#include "say_index_buffer.h"
|
16
14
|
#include "say_index_buffer_slice.h"
|
15
|
+
#include "say_pixel_bus.h"
|
17
16
|
#include "say_drawable.h"
|
18
17
|
#include "say_view.h"
|
19
18
|
#include "say_buffer_renderer.h"
|
data/ext/say_all.h
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
|
4
4
|
/* Dependencies for all of the files */
|
5
5
|
|
6
|
+
/* Data structures */
|
7
|
+
#include "mo.h"
|
8
|
+
|
6
9
|
/* Standard headers */
|
7
10
|
#include <stdlib.h>
|
8
11
|
#include <stdio.h>
|
@@ -72,6 +75,9 @@ void say_error_set(const char *message);
|
|
72
75
|
|
73
76
|
void say_error_clean_up();
|
74
77
|
|
78
|
+
/* Get OpenGL proc */
|
79
|
+
void *say_get_proc(const char *name);
|
80
|
+
|
75
81
|
#define SAY_PI 3.14159265358979323846
|
76
82
|
|
77
83
|
#endif
|
data/ext/say_audio.h
CHANGED
data/ext/say_audio_context.c
CHANGED
@@ -24,8 +24,6 @@ void say_audio_context_ensure() {
|
|
24
24
|
}
|
25
25
|
|
26
26
|
void say_audio_context_clean_up() {
|
27
|
-
/* Can't clean properly on windows... */
|
28
|
-
#ifndef SAY_WIN
|
29
27
|
alcMakeContextCurrent(NULL);
|
30
28
|
|
31
29
|
if (say_audio_context)
|
@@ -35,6 +33,5 @@ void say_audio_context_clean_up() {
|
|
35
33
|
alcCloseDevice(say_audio_device);
|
36
34
|
|
37
35
|
say_audio_context = NULL;
|
38
|
-
say_audio_device = NULL;
|
39
|
-
#endif
|
36
|
+
say_audio_device = NULL;
|
40
37
|
}
|
data/ext/say_basic_type.c
CHANGED
@@ -15,3 +15,27 @@ bool say_rect_eq(say_rect a, say_rect b) {
|
|
15
15
|
bool say_color_eq(say_color a, say_color b) {
|
16
16
|
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
|
17
17
|
}
|
18
|
+
|
19
|
+
say_color *say_flip_color_buffer_copy(say_color *buf, size_t width,
|
20
|
+
size_t height) {
|
21
|
+
size_t line_size = sizeof(say_color) * width;
|
22
|
+
say_color *ret = malloc(line_size * height);
|
23
|
+
|
24
|
+
for (size_t y = 0; y < height; y++)
|
25
|
+
memcpy(&ret[y * width], &buf[(height - y - 1) * width], line_size);
|
26
|
+
|
27
|
+
return ret;
|
28
|
+
}
|
29
|
+
|
30
|
+
void say_flip_color_buffer(say_color *buffer, size_t width, size_t height) {
|
31
|
+
size_t line_size = sizeof(say_color) * width;
|
32
|
+
say_color *temp_line = malloc(line_size);
|
33
|
+
|
34
|
+
for (size_t y = 0; y < height / 2.0; y++) {
|
35
|
+
memcpy(temp_line, &buffer[y * width], line_size);
|
36
|
+
memcpy(&buffer[y * width], &buffer[(height - y - 1) * width], line_size);
|
37
|
+
memcpy(&buffer[(height - y - 1) * width], temp_line, line_size);
|
38
|
+
}
|
39
|
+
|
40
|
+
free(temp_line);
|
41
|
+
}
|
data/ext/say_basic_type.h
CHANGED
@@ -44,4 +44,8 @@ bool say_color_eq(say_color a, say_color b);
|
|
44
44
|
typedef void (*say_destructor)(void *data);
|
45
45
|
typedef void (*say_creator)(void *data);
|
46
46
|
|
47
|
+
say_color *say_flip_color_buffer_copy(say_color *buffer, size_t width,
|
48
|
+
size_t height);
|
49
|
+
void say_flip_color_buffer(say_color *buffer, size_t width, size_t height);
|
50
|
+
|
47
51
|
#endif
|
data/ext/say_buffer.c
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#include "say.h"
|
2
2
|
|
3
3
|
static bool say_has_vao() {
|
4
|
-
return
|
5
|
-
|
4
|
+
return GLEW_ARB_vertex_array_object ||
|
5
|
+
GLEW_VERSION_3_0;
|
6
6
|
}
|
7
7
|
|
8
8
|
static GLuint say_current_vbo = 0;
|
@@ -16,11 +16,11 @@ static void say_vbo_make_current(GLuint vbo) {
|
|
16
16
|
say_current_vbo = vbo;
|
17
17
|
say_vbo_last_context = context;
|
18
18
|
|
19
|
-
|
19
|
+
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
20
20
|
}
|
21
21
|
}
|
22
22
|
|
23
|
-
static GLuint
|
23
|
+
static GLuint say_current_vao = 0;
|
24
24
|
static say_context *say_vao_last_context = NULL;
|
25
25
|
|
26
26
|
typedef struct {
|
@@ -37,6 +37,8 @@ static void say_vao_make_current(GLuint vao) {
|
|
37
37
|
say_vao_last_context = context;
|
38
38
|
|
39
39
|
glBindVertexArray(vao);
|
40
|
+
|
41
|
+
say_index_buffer_rebind();
|
40
42
|
}
|
41
43
|
}
|
42
44
|
|
@@ -72,9 +74,46 @@ static void say_buffer_delete_vao_pair(say_vao_pair *pair) {
|
|
72
74
|
if (say_vao_last_context == pair->context && say_current_vao == pair->vao) {
|
73
75
|
say_current_vao = 0;
|
74
76
|
glDeleteVertexArrays(1, &pair->vao);
|
77
|
+
|
78
|
+
say_index_buffer_rebind();
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
static size_t say_buffer_register_pointer(size_t attr_i, say_vertex_elem_type t,
|
83
|
+
size_t stride, size_t offset) {
|
84
|
+
switch (t) {
|
85
|
+
case SAY_FLOAT:
|
86
|
+
glVertexAttribPointer(attr_i, 1, GL_FLOAT, GL_FALSE, stride,
|
87
|
+
(void*)offset);
|
88
|
+
return offset + sizeof(GLfloat);
|
89
|
+
case SAY_INT:
|
90
|
+
glVertexAttribPointer(attr_i, 1, GL_INT, GL_FALSE, stride,
|
91
|
+
(void*)offset);
|
92
|
+
return offset + sizeof(GLint);
|
93
|
+
case SAY_UBYTE:
|
94
|
+
glVertexAttribPointer(attr_i, 1, GL_UNSIGNED_BYTE, GL_FALSE, stride,
|
95
|
+
(void*)offset);
|
96
|
+
return offset + sizeof(GLubyte);
|
97
|
+
case SAY_BOOL:
|
98
|
+
glVertexAttribPointer(attr_i, 1, GL_INT, GL_FALSE, stride,
|
99
|
+
(void*)offset);
|
100
|
+
return offset + sizeof(GLint);
|
101
|
+
|
102
|
+
case SAY_COLOR:
|
103
|
+
glVertexAttribPointer(attr_i, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride,
|
104
|
+
(void*)offset);
|
105
|
+
return offset + sizeof(GLubyte) * 4;
|
106
|
+
case SAY_VECTOR2:
|
107
|
+
glVertexAttribPointer(attr_i, 2, GL_FLOAT, GL_FALSE, stride,
|
108
|
+
(void*)offset);
|
109
|
+
return offset + sizeof(GLfloat) * 2;
|
110
|
+
case SAY_VECTOR3:
|
111
|
+
glVertexAttribPointer(attr_i, 3, GL_FLOAT, GL_FALSE, stride,
|
112
|
+
(void*)offset);
|
113
|
+
return offset + sizeof(GLfloat) * 3;
|
75
114
|
}
|
76
115
|
|
77
|
-
|
116
|
+
return offset;
|
78
117
|
}
|
79
118
|
|
80
119
|
static void say_buffer_setup_pointer(say_buffer *buf) {
|
@@ -82,64 +121,69 @@ static void say_buffer_setup_pointer(say_buffer *buf) {
|
|
82
121
|
|
83
122
|
say_vertex_type *type = say_get_vertex_type(buf->vtype);
|
84
123
|
|
85
|
-
size_t count
|
86
|
-
|
124
|
+
size_t count = say_vertex_type_get_elem_count(type);
|
125
|
+
if (count == 0) /* No attrbutes to set */
|
126
|
+
return;
|
87
127
|
|
128
|
+
size_t stride = say_vertex_type_get_size(type);
|
88
129
|
size_t offset = 0;
|
89
130
|
|
131
|
+
size_t instance_stride = say_vertex_type_get_instance_size(type);
|
132
|
+
size_t instance_offset = 0;
|
133
|
+
|
134
|
+
/*
|
135
|
+
* This fixes a bug on OSX (with OpenGL 2.1). Nothing is drawn unless vertex
|
136
|
+
* attribute 0 is enabled.
|
137
|
+
*
|
138
|
+
* We set its data to the same as those used by the first element to ensure
|
139
|
+
* memory we do not own isn't accessed.
|
140
|
+
*/
|
141
|
+
say_vertex_elem_type t = say_vertex_type_get_type(type, 0);
|
142
|
+
|
143
|
+
if (say_vertex_type_is_per_instance(type, 0)) {
|
144
|
+
say_vbo_make_current(buf->instance_vbo);
|
145
|
+
say_buffer_register_pointer(0, t, instance_stride, instance_offset);
|
146
|
+
}
|
147
|
+
else {
|
148
|
+
say_vbo_make_current(buf->vbo);
|
149
|
+
say_buffer_register_pointer(0, t, stride, offset);
|
150
|
+
}
|
151
|
+
|
152
|
+
glEnableVertexAttribArray(0);
|
153
|
+
|
90
154
|
size_t i = 0;
|
91
155
|
for (; i < count; i++) {
|
92
|
-
|
156
|
+
t = say_vertex_type_get_type(type, i);
|
93
157
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
offset
|
102
|
-
break;
|
103
|
-
case SAY_UBYTE:
|
104
|
-
glVertexAttribPointerARB(i, 1, GL_UNSIGNED_BYTE, GL_FALSE, stride,
|
105
|
-
(void*)offset);
|
106
|
-
offset += sizeof(GLubyte);
|
107
|
-
break;
|
108
|
-
case SAY_BOOL:
|
109
|
-
glVertexAttribPointerARB(i, 1, GL_INT, GL_FALSE, stride, (void*)offset);
|
110
|
-
offset += sizeof(GLint);
|
111
|
-
break;
|
112
|
-
|
113
|
-
case SAY_COLOR:
|
114
|
-
glVertexAttribPointerARB(i, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride,
|
115
|
-
(void*)offset);
|
116
|
-
offset += sizeof(GLubyte) * 4;
|
117
|
-
break;
|
118
|
-
case SAY_VECTOR2:
|
119
|
-
glVertexAttribPointerARB(i, 2, GL_FLOAT, GL_FALSE, stride,
|
120
|
-
(void*)offset);
|
121
|
-
offset += sizeof(GLfloat) * 2;
|
122
|
-
break;
|
123
|
-
case SAY_VECTOR3:
|
124
|
-
glVertexAttribPointerARB(i, 3, GL_FLOAT, GL_FALSE, stride,
|
125
|
-
(void*)offset);
|
126
|
-
offset += sizeof(GLfloat) * 3;
|
127
|
-
break;
|
158
|
+
if (say_vertex_type_is_per_instance(type, i)) {
|
159
|
+
say_vbo_make_current(buf->instance_vbo);
|
160
|
+
instance_offset = say_buffer_register_pointer(i + 1, t, instance_stride,
|
161
|
+
instance_offset);
|
162
|
+
}
|
163
|
+
else {
|
164
|
+
say_vbo_make_current(buf->vbo);
|
165
|
+
offset = say_buffer_register_pointer(i + 1, t, stride, offset);
|
128
166
|
}
|
129
167
|
|
130
|
-
|
168
|
+
glEnableVertexAttribArray(i + 1);
|
169
|
+
if (glVertexAttribDivisor) {
|
170
|
+
if (say_vertex_type_is_per_instance(type, i))
|
171
|
+
glVertexAttribDivisor(i + 1, 1);
|
172
|
+
else
|
173
|
+
glVertexAttribDivisor(i + 1, 0);
|
174
|
+
}
|
131
175
|
}
|
132
176
|
|
133
177
|
/*
|
134
178
|
* Say will always use all the attribs. Disable all of them until
|
135
179
|
* finding one that is already disabled.
|
136
180
|
*/
|
137
|
-
for (; i <
|
181
|
+
for (; i < GL_MAX_VERTEX_ATTRIBS - 1; i++) {
|
138
182
|
GLint enabled;
|
139
|
-
|
183
|
+
glGetVertexAttribiv(i + 1, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled);
|
140
184
|
|
141
185
|
if (enabled)
|
142
|
-
|
186
|
+
glDisableVertexAttribArray(i + 1);
|
143
187
|
else
|
144
188
|
break;
|
145
189
|
}
|
@@ -147,29 +191,24 @@ static void say_buffer_setup_pointer(say_buffer *buf) {
|
|
147
191
|
|
148
192
|
static void say_buffer_build_vao(say_buffer *buf, GLuint vao) {
|
149
193
|
say_vao_make_current(vao);
|
150
|
-
glBindBufferARB(GL_ARRAY_BUFFER_ARB, buf->vbo); /* forcefully bind */
|
151
194
|
say_buffer_setup_pointer(buf);
|
152
195
|
}
|
153
196
|
|
154
197
|
static GLuint say_buffer_get_vao(say_buffer *buf) {
|
155
198
|
say_context *ctxt = say_context_current();
|
156
|
-
uint32_t count = ctxt->count;
|
157
|
-
|
158
|
-
say_vao_pair *pair = say_table_get(buf->vaos, count);
|
159
199
|
|
160
|
-
if (!
|
161
|
-
pair
|
162
|
-
|
200
|
+
if (!mo_hash_has_key(buf->vaos, &ctxt)) {
|
201
|
+
say_vao_pair pair;
|
202
|
+
pair.context = ctxt;
|
203
|
+
glGenVertexArrays(1, &pair.vao);
|
204
|
+
say_buffer_build_vao(buf, pair.vao);
|
163
205
|
|
164
|
-
|
206
|
+
mo_hash_set(buf->vaos, &ctxt, &pair);
|
165
207
|
|
166
|
-
|
167
|
-
say_buffer_build_vao(buf, pair->vao);
|
168
|
-
|
169
|
-
return pair->vao;
|
208
|
+
return pair.vao;
|
170
209
|
}
|
171
210
|
else {
|
172
|
-
return
|
211
|
+
return mo_hash_get_ptr(buf->vaos, &ctxt, say_vao_pair)->vao;
|
173
212
|
}
|
174
213
|
}
|
175
214
|
|
@@ -178,23 +217,40 @@ say_buffer *say_buffer_create(size_t vtype, GLenum type, size_t size) {
|
|
178
217
|
|
179
218
|
say_buffer *buf = (say_buffer*)malloc(sizeof(say_buffer));
|
180
219
|
|
181
|
-
if (say_has_vao())
|
182
|
-
buf->vaos =
|
220
|
+
if (say_has_vao()) {
|
221
|
+
buf->vaos = mo_hash_create(sizeof(say_context*), sizeof(say_vao_pair));
|
222
|
+
buf->vaos->release = (say_destructor)say_buffer_delete_vao_pair;
|
223
|
+
buf->vaos->hash_of = mo_hash_of_pointer;
|
224
|
+
buf->vaos->key_cmp = mo_hash_pointer_cmp;
|
225
|
+
|
226
|
+
}
|
183
227
|
else
|
184
228
|
buf->vaos = NULL;
|
185
229
|
|
186
230
|
buf->vtype = vtype;
|
187
231
|
|
188
|
-
|
232
|
+
glGenBuffers(1, &buf->vbo);
|
189
233
|
say_vbo_make_current(buf->vbo);
|
190
234
|
|
191
235
|
buf->type = type;
|
192
236
|
|
193
|
-
|
194
|
-
|
195
|
-
|
237
|
+
say_vertex_type *vtype_ref = say_get_vertex_type(vtype);
|
238
|
+
size_t byte_size = say_vertex_type_get_size(vtype_ref);
|
239
|
+
mo_array_init(&buf->buffer, byte_size);
|
240
|
+
mo_array_resize(&buf->buffer, size);
|
241
|
+
|
242
|
+
glBufferData(GL_ARRAY_BUFFER, size * byte_size, NULL, type);
|
196
243
|
|
197
|
-
|
244
|
+
buf->instance_vbo = 0;
|
245
|
+
buf->instance_buffer = NULL;
|
246
|
+
|
247
|
+
if (say_vertex_type_has_instance_data(vtype_ref)) {
|
248
|
+
glGenBuffers(1, &buf->instance_vbo);
|
249
|
+
say_vbo_make_current(buf->instance_vbo);
|
250
|
+
|
251
|
+
byte_size = say_vertex_type_get_instance_size(vtype_ref);
|
252
|
+
buf->instance_buffer = mo_array_create(byte_size);
|
253
|
+
}
|
198
254
|
|
199
255
|
return buf;
|
200
256
|
}
|
@@ -203,19 +259,34 @@ void say_buffer_free(say_buffer *buf) {
|
|
203
259
|
say_context_ensure();
|
204
260
|
|
205
261
|
if (buf->vaos)
|
206
|
-
|
262
|
+
mo_hash_free(buf->vaos);
|
207
263
|
else
|
208
264
|
say_buffer_will_delete(buf);
|
209
265
|
|
210
266
|
say_vbo_will_delete(buf->vbo);
|
211
|
-
|
267
|
+
glDeleteBuffers(1, &buf->vbo);
|
268
|
+
|
269
|
+
if (buf->instance_vbo) {
|
270
|
+
say_vbo_will_delete(buf->instance_vbo);
|
271
|
+
glDeleteBuffers(1, &buf->instance_vbo);
|
272
|
+
|
273
|
+
mo_array_free(buf->instance_buffer);
|
274
|
+
}
|
212
275
|
|
213
|
-
|
276
|
+
mo_array_release(&buf->buffer);
|
214
277
|
free(buf);
|
215
278
|
}
|
216
279
|
|
280
|
+
bool say_buffer_has_instance(say_buffer *buf) {
|
281
|
+
return buf->instance_buffer != NULL;
|
282
|
+
}
|
283
|
+
|
217
284
|
void *say_buffer_get_vertex(say_buffer *buf, size_t id) {
|
218
|
-
return
|
285
|
+
return mo_array_at(&buf->buffer, id);
|
286
|
+
}
|
287
|
+
|
288
|
+
void *say_buffer_get_instance(say_buffer *buf, size_t id) {
|
289
|
+
return mo_array_at(buf->instance_buffer, id);
|
219
290
|
}
|
220
291
|
|
221
292
|
void say_buffer_bind(say_buffer *buf) {
|
@@ -227,51 +298,109 @@ void say_buffer_bind(say_buffer *buf) {
|
|
227
298
|
say_buffer_make_current(buf);
|
228
299
|
}
|
229
300
|
|
301
|
+
void say_buffer_bind_vbo(say_buffer *buf) {
|
302
|
+
say_context_ensure();
|
303
|
+
say_vbo_make_current(buf->vbo);
|
304
|
+
}
|
305
|
+
|
306
|
+
void say_buffer_bind_instance_vbo(say_buffer *buf) {
|
307
|
+
say_context_ensure();
|
308
|
+
say_vbo_make_current(buf->instance_vbo);
|
309
|
+
}
|
310
|
+
|
230
311
|
void say_buffer_unbind() {
|
231
|
-
|
312
|
+
say_context_ensure();
|
232
313
|
|
233
314
|
if (say_has_vao())
|
234
315
|
say_vao_make_current(0);
|
235
316
|
else { /* disable vertex attribs */
|
236
|
-
for (size_t i =
|
317
|
+
for (size_t i = 1; i < GL_MAX_VERTEX_ATTRIBS; i++) {
|
237
318
|
GLint enabled;
|
238
|
-
|
319
|
+
glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &enabled);
|
239
320
|
|
240
321
|
if (enabled)
|
241
|
-
|
322
|
+
glDisableVertexAttribArray(i);
|
242
323
|
else
|
243
324
|
break;
|
244
325
|
}
|
245
326
|
}
|
246
327
|
}
|
247
328
|
|
329
|
+
void say_buffer_unbind_vbo() {
|
330
|
+
say_context_ensure();
|
331
|
+
say_vbo_make_current(0);
|
332
|
+
}
|
333
|
+
|
248
334
|
void say_buffer_update_part(say_buffer *buf, size_t id, size_t size) {
|
249
335
|
if (size == 0) return;
|
250
336
|
|
251
337
|
say_context_ensure();
|
252
|
-
say_buffer_bind(buf);
|
253
338
|
|
254
|
-
size_t byte_size =
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
339
|
+
size_t byte_size = buf->buffer.el_size;
|
340
|
+
say_vbo_make_current(buf->vbo);
|
341
|
+
glBufferSubData(GL_ARRAY_BUFFER,
|
342
|
+
byte_size * id,
|
343
|
+
byte_size * size,
|
344
|
+
say_buffer_get_vertex(buf, id));
|
259
345
|
}
|
260
346
|
|
261
347
|
void say_buffer_update(say_buffer *buf) {
|
262
|
-
say_buffer_update_part(buf, 0,
|
348
|
+
say_buffer_update_part(buf, 0, buf->buffer.size);
|
263
349
|
}
|
264
350
|
|
265
351
|
size_t say_buffer_get_size(say_buffer *buf) {
|
266
|
-
return
|
352
|
+
return buf->buffer.size;
|
267
353
|
}
|
268
354
|
|
269
355
|
void say_buffer_resize(say_buffer *buf, size_t size) {
|
270
|
-
|
356
|
+
mo_array_resize(&buf->buffer, size);
|
357
|
+
|
358
|
+
say_context_ensure();
|
359
|
+
say_vbo_make_current(buf->vbo);
|
360
|
+
glBufferData(GL_ARRAY_BUFFER,
|
361
|
+
size * buf->buffer.el_size,
|
362
|
+
say_buffer_get_vertex(buf, 0),
|
363
|
+
buf->type);
|
364
|
+
}
|
365
|
+
|
366
|
+
void say_buffer_update_instance_part(say_buffer *buf, size_t id,
|
367
|
+
size_t size) {
|
368
|
+
if (size == 0) return;
|
369
|
+
|
370
|
+
say_context_ensure();
|
371
|
+
|
372
|
+
size_t byte_size = buf->instance_buffer->el_size;
|
373
|
+
say_vbo_make_current(buf->instance_vbo);
|
374
|
+
glBufferSubData(GL_ARRAY_BUFFER,
|
375
|
+
byte_size * id,
|
376
|
+
byte_size * size,
|
377
|
+
say_buffer_get_instance(buf, id));
|
378
|
+
}
|
379
|
+
|
380
|
+
void say_buffer_update_instance(say_buffer *buf) {
|
381
|
+
say_buffer_update_instance_part(buf, 0,
|
382
|
+
buf->instance_buffer->size);
|
383
|
+
}
|
384
|
+
|
385
|
+
size_t say_buffer_get_instance_size(say_buffer *buf) {
|
386
|
+
return buf->instance_buffer->size;
|
387
|
+
}
|
388
|
+
|
389
|
+
void say_buffer_resize_instance(say_buffer *buf, size_t size) {
|
390
|
+
mo_array_resize(buf->instance_buffer, size);
|
391
|
+
|
392
|
+
say_context_ensure();
|
393
|
+
say_vbo_make_current(buf->instance_vbo);
|
394
|
+
glBufferData(GL_ARRAY_BUFFER,
|
395
|
+
size * buf->instance_buffer->el_size,
|
396
|
+
say_buffer_get_instance(buf, 0),
|
397
|
+
buf->type);
|
398
|
+
}
|
399
|
+
|
400
|
+
GLuint say_buffer_get_vbo(say_buffer *buf) {
|
401
|
+
return buf->vbo;
|
402
|
+
}
|
271
403
|
|
272
|
-
|
273
|
-
|
274
|
-
size * say_array_get_elem_size(buf->buffer),
|
275
|
-
say_buffer_get_vertex(buf, 0),
|
276
|
-
buf->type);
|
404
|
+
GLuint say_buffer_get_instance_vbo(say_buffer *buf) {
|
405
|
+
return buf->instance_vbo;
|
277
406
|
}
|