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
@@ -5,8 +5,9 @@
5
5
  #include "say_image.h"
6
6
 
7
7
  typedef struct {
8
- GLuint fbo, rbo;
9
- say_image *img;
8
+ mo_hash *fbos;
9
+ GLuint rbo;
10
+ say_image *img;
10
11
  say_target *target;
11
12
  } say_image_target;
12
13
 
@@ -11,7 +11,7 @@ static void say_ibo_make_current(GLuint ibo) {
11
11
  say_current_ibo = ibo;
12
12
  say_ibo_last_context = context;
13
13
 
14
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ibo);
14
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
15
15
  }
16
16
  }
17
17
 
@@ -26,15 +26,15 @@ say_index_buffer *say_index_buffer_create(GLenum type, size_t size) {
26
26
 
27
27
  say_index_buffer *buf = malloc(sizeof(say_index_buffer));
28
28
 
29
- glGenBuffersARB(1, &buf->ibo);
29
+ glGenBuffers(1, &buf->ibo);
30
30
  buf->type = type;
31
31
 
32
- buf->buffer = say_array_create(sizeof(GLuint), NULL, NULL);
33
- say_array_resize(buf->buffer, size);
32
+ mo_array_init(&buf->buffer, sizeof(GLuint));
33
+ mo_array_resize(&buf->buffer, size);
34
34
 
35
35
  say_ibo_make_current(buf->ibo);
36
- glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, size * sizeof(GLuint),
37
- NULL, type);
36
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, size * sizeof(GLuint),
37
+ NULL, type);
38
38
 
39
39
  return buf;
40
40
  }
@@ -43,8 +43,8 @@ void say_index_buffer_free(say_index_buffer *buf) {
43
43
  say_context_ensure();
44
44
 
45
45
  say_ibo_will_delete(buf->ibo);
46
- glDeleteBuffersARB(1, &buf->ibo);
47
- say_array_free(buf->buffer);
46
+ glDeleteBuffers(1, &buf->ibo);
47
+ mo_array_release(&buf->buffer);
48
48
  free(buf);
49
49
  }
50
50
 
@@ -53,38 +53,50 @@ void say_index_buffer_bind(say_index_buffer *buf) {
53
53
  say_ibo_make_current(buf->ibo);
54
54
  }
55
55
 
56
- void say_index_buffer_unbind(say_index_buffer *buf) {
56
+ void say_index_buffer_unbind() {
57
57
  say_context_ensure();
58
58
  say_ibo_make_current(0);
59
59
  }
60
60
 
61
+ void say_index_buffer_rebind() {
62
+ if (say_ibo_last_context == say_context_current())
63
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, say_current_ibo);
64
+ }
65
+
61
66
  void say_index_buffer_update_part(say_index_buffer *buf, size_t index,
62
67
  size_t size) {
63
68
  say_context_ensure();
64
69
 
65
70
  say_index_buffer_bind(buf);
66
- glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
67
- index * sizeof(GLuint),
68
- size * sizeof(GLuint),
69
- say_array_get(buf->buffer, index));
71
+ glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,
72
+ index * sizeof(GLuint),
73
+ size * sizeof(GLuint),
74
+ mo_array_at(&buf->buffer, index));
70
75
  }
71
76
 
72
77
  void say_index_buffer_update(say_index_buffer *buf) {
73
- say_index_buffer_update_part(buf, 0, say_array_get_size(buf->buffer));
78
+ say_index_buffer_update_part(buf, 0, buf->buffer.size);
74
79
  }
75
80
 
76
81
  size_t say_index_buffer_get_size(say_index_buffer *buf) {
77
- return say_array_get_size(buf->buffer);
82
+ return buf->buffer.size;
78
83
  }
79
84
 
80
85
  void say_index_buffer_resize(say_index_buffer *buf, size_t size) {
81
86
  say_context_ensure();
82
87
 
83
- say_array_resize(buf->buffer, size);
84
- glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, size * sizeof(GLuint), NULL,
85
- buf->type);
88
+ mo_array_resize(&buf->buffer, size);
89
+ mo_array_shrink(&buf->buffer);
90
+
91
+ say_index_buffer_bind(buf);
92
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, size * sizeof(GLuint),
93
+ mo_array_at(&buf->buffer, 0), buf->type);
86
94
  }
87
95
 
88
96
  GLuint *say_index_buffer_get(say_index_buffer *buf, size_t i) {
89
- return say_array_get(buf->buffer, i);
97
+ return mo_array_get_ptr(&buf->buffer, i, GLuint);
98
+ }
99
+
100
+ GLuint say_index_buffer_get_ibo(say_index_buffer *buf) {
101
+ return buf->ibo;
90
102
  }
@@ -2,13 +2,12 @@
2
2
  #define SAY_INDEX_BUFFER_H_
3
3
 
4
4
  #include "say_basic_type.h"
5
- #include "say_array.h"
6
5
 
7
6
  typedef struct {
8
7
  GLuint ibo;
9
8
  GLenum type;
10
9
 
11
- say_array *buffer;
10
+ mo_array buffer;
12
11
  } say_index_buffer;
13
12
 
14
13
  say_index_buffer *say_index_buffer_create(GLenum type, size_t size);
@@ -16,6 +15,7 @@ void say_index_buffer_free(say_index_buffer *buf);
16
15
 
17
16
  void say_index_buffer_bind(say_index_buffer *buf);
18
17
  void say_index_buffer_unbind();
18
+ void say_index_buffer_rebind();
19
19
 
20
20
  void say_index_buffer_update_part(say_index_buffer *buf, size_t index,
21
21
  size_t size);
@@ -26,4 +26,6 @@ void say_index_buffer_resize(say_index_buffer *buf, size_t size);
26
26
 
27
27
  GLuint *say_index_buffer_get(say_index_buffer *buf, size_t i);
28
28
 
29
+ GLuint say_index_buffer_get_ibo(say_index_buffer *buf);
30
+
29
31
  #endif
@@ -12,15 +12,15 @@ typedef struct {
12
12
 
13
13
  typedef struct {
14
14
  say_index_buffer *buf;
15
- say_array *ranges;
15
+ mo_list *ranges;
16
16
  } say_global_ibo;
17
17
 
18
- static say_array *say_index_buffers = NULL;
18
+ static mo_array *say_index_buffers = NULL;
19
19
 
20
20
  static say_global_ibo say_global_ibo_create(size_t size) {
21
21
  say_global_ibo ret;
22
22
  ret.buf = say_index_buffer_create(SAY_STREAM, size);
23
- ret.ranges = say_array_create(sizeof(say_range), NULL, NULL);
23
+ ret.ranges = NULL;
24
24
 
25
25
  return ret;
26
26
  }
@@ -29,90 +29,95 @@ static void say_global_ibo_free(void *data) {
29
29
  say_global_ibo *ibo = (say_global_ibo*)data;
30
30
 
31
31
  say_index_buffer_free(ibo->buf);
32
- say_array_free(ibo->ranges);
32
+ if (ibo->ranges) mo_list_free(ibo->ranges);
33
33
  }
34
34
 
35
35
  static say_global_ibo *say_global_ibo_at(size_t index) {
36
36
  if (!say_index_buffers)
37
37
  return NULL;
38
- return say_array_get(say_index_buffers, index);
38
+ return mo_array_at(say_index_buffers, index);
39
39
  }
40
40
 
41
- static size_t say_global_ibo_insert(say_global_ibo *ibo, size_t i,
41
+ static bool say_global_ibo_fit_into(say_global_ibo *ibo, size_t used,
42
42
  size_t size) {
43
- say_range tmp = say_make_range(0, size);
44
- say_array_insert(ibo->ranges, i, &tmp);
43
+ size_t buffer_size = say_index_buffer_get_size(ibo->buf);
44
+
45
+ if (used + size < buffer_size)
46
+ return true;
47
+ else if (used + size < SAY_BUFFER_MAX_SIZE &&
48
+ buffer_size <= SAY_BUFFER_MAX_SIZE) {
49
+ size_t sought_size = used + size;
50
+ size_t right_size = buffer_size;
45
51
 
46
- say_range *range = say_array_get(ibo->ranges, i);
52
+ while (right_size < sought_size) right_size *= 2;
47
53
 
48
- if (i != 0) {
49
- say_range *prev = say_array_get(ibo->ranges, i - 1);
50
- range->loc = prev->loc + prev->size;
54
+ say_index_buffer_resize(ibo->buf, right_size);
55
+ return true;
51
56
  }
57
+ else
58
+ return false;
59
+ }
60
+
61
+ static size_t say_global_ibo_prepend(say_global_ibo *ibo, size_t size) {
62
+ say_range range = say_make_range(0, size);
63
+ ibo->ranges = mo_list_prepend(ibo->ranges, &range);
64
+ return 0;
65
+ }
66
+
67
+ static size_t say_global_ibo_insert(mo_list *list, size_t size) {
68
+ say_range *range = mo_list_data_ptr(list, say_range);
69
+ say_range tmp = say_make_range(range->loc + range->size, size);
52
70
 
53
- return range->loc;
71
+ mo_list_insert(list, &tmp);
72
+ return tmp.loc;
54
73
  }
55
74
 
56
75
  static size_t say_global_ibo_find_in(say_global_ibo *ibo, size_t size) {
57
- size_t buffer_size = say_index_buffer_get_size(ibo->buf);
76
+ if (!ibo->ranges && say_global_ibo_fit_into(ibo, 0, size)) {
77
+ ibo->ranges = mo_list_create(sizeof(say_range));
78
+ say_range *range = mo_list_data_ptr(ibo->ranges, say_range);
79
+ *range = say_make_range(0, size);
80
+ return 0;
81
+ }
58
82
 
59
- size_t ary_size = say_array_get_size(ibo->ranges);
60
- say_range *first = say_array_get(ibo->ranges, 0);
83
+ say_range *first = mo_list_data_ptr(ibo->ranges, say_range);
61
84
 
62
85
  /* There's room at the begin of the buffer */
63
- if (ary_size == 0 || first->loc >= size) {
64
- return say_global_ibo_insert(ibo, 0, size);
86
+ if (first->loc >= size) {
87
+ return say_global_ibo_prepend(ibo, size);
65
88
  }
66
89
 
67
- say_range *current = first, *next = NULL;
68
-
69
- for (size_t i = 0; i < ary_size - 1; i++) {
70
- next = say_array_get(ibo->ranges, i + 1);
90
+ mo_list *it = ibo->ranges;
91
+ for (; it->next; it = it->next) {
92
+ say_range *current = mo_list_data_ptr(it, say_range);
93
+ say_range *next = mo_list_data_ptr(it->next, say_range);
71
94
 
72
95
  size_t begin = current->loc + current->size;
73
96
  size_t end = next->loc;
74
97
 
75
98
  /* There's enough room between those two elements */
76
- if (end - begin >= size) {
77
- return say_global_ibo_insert(ibo, i + 1, size);
78
- }
79
-
80
- current = next;
99
+ if (end - begin >= size)
100
+ return say_global_ibo_insert(it, size);
81
101
  }
82
102
 
83
- say_range *last = say_array_get(ibo->ranges, ary_size - 1);
103
+ say_range *last = mo_list_data_ptr(it, say_range);
84
104
 
85
105
  /* There's enough room at the end of the buffer */
86
- if ((last->loc + last->size + size) < say_index_buffer_get_size(ibo->buf)) {
87
- return say_global_ibo_insert(ibo, ary_size, size);
88
- }
89
-
90
- /* Not enough room here. But perhaps we can make some? */
91
- if (buffer_size < SAY_BUFFER_MAX_SIZE && size <= SAY_BUFFER_MAX_SIZE) {
92
- size_t sought_size = last->loc + last->size + size;
93
- size_t right_size = say_index_buffer_get_size(ibo->buf);
94
-
95
- while (right_size < sought_size)
96
- right_size *= 2;
97
-
98
- say_index_buffer_resize(ibo->buf, right_size);
99
- return say_global_ibo_insert(ibo, ary_size, size);
100
- }
106
+ if (say_global_ibo_fit_into(ibo, last->loc + last->size, size))
107
+ return say_global_ibo_insert(it, size);
101
108
  else
102
109
  return SAY_MAX_SIZE;
103
110
  }
104
111
 
105
112
  static size_t say_global_ibo_find(size_t size, size_t *buf_id) {
106
113
  if (!say_index_buffers) {
107
- say_index_buffers = say_array_create(sizeof(say_global_ibo),
108
- say_global_ibo_free,
109
- NULL);
114
+ say_index_buffers = mo_array_create(sizeof(say_global_ibo));
115
+ say_index_buffers->release = say_global_ibo_free;
110
116
  }
111
117
 
112
- size_t i = 0;
113
- for (say_global_ibo *ibo = say_array_get(say_index_buffers, 0);
114
- ibo;
115
- say_array_next(say_index_buffers, (void**)&ibo)) {
118
+ for (size_t i = 0; i < say_index_buffers->size; i++) {
119
+ say_global_ibo *ibo = mo_array_at(say_index_buffers, 0);
120
+
116
121
  size_t loc;
117
122
  if ((loc = say_global_ibo_find_in(ibo, size)) != SAY_MAX_SIZE) {
118
123
  *buf_id = i;
@@ -132,34 +137,35 @@ static size_t say_global_ibo_find(size_t size, size_t *buf_id) {
132
137
  }
133
138
 
134
139
  say_global_ibo ibo = say_global_ibo_create(buf_size);
135
- say_array_push(say_index_buffers, &ibo);
140
+ mo_array_push(say_index_buffers, &ibo);
136
141
 
137
- *buf_id = say_array_get_size(say_index_buffers) - 1;
142
+ *buf_id = say_index_buffers->size - 1;
138
143
  return say_global_ibo_find_in(say_global_ibo_at(*buf_id), size);
139
144
  }
140
145
 
141
- static void say_global_ibo_delete_at(say_global_ibo *ibo, size_t loc) {
146
+ static void say_global_ibo_delete_at(say_global_ibo *ibo, size_t loc,
147
+ size_t range_size) {
142
148
  if (!ibo)
143
149
  return;
144
150
 
145
- size_t n = 0, size = say_array_get_size(ibo->ranges);
146
- for (; n < size; n++) {
147
- say_range *range = say_array_get(ibo->ranges, n);
148
- if (range->loc == loc)
149
- break;
150
- }
151
+ for (mo_list *it = ibo->ranges; it; it = it->next) {
152
+ say_range *range = mo_list_data_ptr(it, say_range);
153
+ if (range->loc == loc && range->size == range_size) {
154
+ mo_list *next = it->next;
155
+ mo_list_delete(it);
151
156
 
152
- if (n == size)
153
- return; /* Element could not be found */
157
+ if (it == ibo->ranges) ibo->ranges = next;
154
158
 
155
- say_array_delete(ibo->ranges, n);
159
+ return;
160
+ }
161
+ }
156
162
  }
157
163
 
158
164
  static void say_global_ibo_reduce_size(say_global_ibo *ibo, size_t loc,
159
- size_t size) {
160
- for (say_range *range = say_array_get(ibo->ranges, 0); range;
161
- say_array_next(ibo->ranges, (void**)&range)) {
162
- if (range->loc == loc) {
165
+ size_t old_size, size_t size) {
166
+ for (mo_list *it = ibo->ranges; it; it = it->next) {
167
+ say_range *range = mo_list_data_ptr(it, say_range);
168
+ if (range->loc == loc && range->size == old_size) {
163
169
  range->size = size;
164
170
  return;
165
171
  }
@@ -180,19 +186,21 @@ say_index_buffer_slice *say_index_buffer_slice_create(size_t size) {
180
186
  }
181
187
 
182
188
  void say_index_buffer_slice_free(say_index_buffer_slice *slice) {
183
- say_global_ibo_delete_at(say_global_ibo_at(slice->buf_id), slice->loc);
189
+ say_global_ibo_delete_at(say_global_ibo_at(slice->buf_id), slice->loc,
190
+ slice->size);
184
191
  free(slice);
185
192
  }
186
193
 
187
194
  void say_index_buffer_slice_recreate(say_index_buffer_slice *slice,
188
195
  size_t size) {
189
196
  if (size > slice->size) {
190
- say_global_ibo_delete_at(say_global_ibo_at(slice->buf_id), slice->loc);
197
+ say_global_ibo_delete_at(say_global_ibo_at(slice->buf_id), slice->loc,
198
+ slice->size);
191
199
  slice->loc = say_global_ibo_find(size, &slice->buf_id);
192
200
  }
193
201
  else {
194
202
  say_global_ibo_reduce_size(say_global_ibo_at(slice->buf_id),
195
- slice->loc, size);
203
+ slice->loc, slice->size, size);
196
204
  }
197
205
 
198
206
  slice->size = size;
@@ -221,7 +229,7 @@ void say_index_buffer_slice_bind(say_index_buffer_slice *slice) {
221
229
 
222
230
  void say_index_buffer_slice_clean_up() {
223
231
  if (say_index_buffers) {
224
- say_array_free(say_index_buffers);
232
+ mo_array_free(say_index_buffers);
225
233
  say_index_buffers = NULL;
226
234
  }
227
235
  }
@@ -78,12 +78,12 @@ static void *say_music_playback_thread(say_music *music) {
78
78
  }
79
79
  }
80
80
  }
81
-
81
+
82
82
  /* sleep for 0.25s */
83
83
  #ifdef SAY_WIN
84
84
  Sleep(250);
85
85
  #else
86
- usleep(250 * 1000);
86
+ usleep(250 * 1000);
87
87
  #endif
88
88
  }
89
89
 
@@ -116,7 +116,9 @@ say_music *say_music_create() {
116
116
  void say_music_free(say_music *music) {
117
117
  music->continue_running = false;
118
118
 
119
+ #ifndef SAY_WIN
119
120
  say_thread_join(music->thread);
121
+ #endif
120
122
  say_thread_free(music->thread);
121
123
 
122
124
  alSourceStop(music->src->src);
@@ -2,8 +2,9 @@
2
2
 
3
3
  #import <Cocoa/Cocoa.h>
4
4
 
5
+ #include "mo.h"
6
+
5
7
  struct say_event;
6
- struct say_array;
7
8
  struct say_image;
8
9
 
9
10
  void say_osx_flip_pool();
@@ -31,7 +32,7 @@ void say_osx_flip_pool();
31
32
  NSWindow *window;
32
33
  NSOpenGLView *view;
33
34
 
34
- struct say_array *events;
35
+ mo_array events;
35
36
 
36
37
  BOOL allow_close;
37
38
 
@@ -8,6 +8,8 @@
8
8
  static NSOpenGLPixelFormat *format = nil;
9
9
 
10
10
  if (!format) {
11
+ say_context_config *conf = say_context_get_config();
12
+
11
13
  NSOpenGLPixelFormatAttribute attr[] = {
12
14
  NSOpenGLPFAClosestPolicy,
13
15
  NSOpenGLPFADoubleBuffer,
@@ -16,11 +18,43 @@
16
18
  NSOpenGLPFAColorSize, 24,
17
19
  NSOpenGLPFAAlphaSize, 8,
18
20
 
19
- NSOpenGLPFADepthSize, 24,
21
+ /*
22
+ * Next elements must be set depending on user configuration.
23
+ */
24
+
25
+ 0, 0, /* depth */
26
+ 0, 0, /* stencil */
27
+
28
+ 0, 0, /* profile */
20
29
 
21
- 0
30
+ 0 /* terminator */
22
31
  };
23
32
 
33
+ size_t i = 7;
34
+
35
+ if (conf->depth_size) {
36
+ attr[i + 0] = NSOpenGLPFADepthSize;
37
+ attr[i + 1] = conf->depth_size;
38
+
39
+ i += 2;
40
+ }
41
+
42
+ if (conf->stencil_size) {
43
+ attr[i + 0] = NSOpenGLPFAStencilSize;
44
+ attr[i + 1] = conf->stencil_size;
45
+
46
+ i += 2;
47
+ }
48
+
49
+ #ifdef AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER
50
+ if (conf->core_profile) { /* OpenGL 3.2! */
51
+ attr[i + 0] = NSOpenGLPFAOpenGLProfile;
52
+ attr[i + 1] = NSOpenGLProfileVersion3_2Core;
53
+
54
+ i += 2;
55
+ }
56
+ #endif
57
+
24
58
  format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr];
25
59
  }
26
60
 
@@ -62,10 +96,9 @@
62
96
  }
63
97
 
64
98
  - (void)dealloc {
65
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
99
+ say_osx_flip_pool();
66
100
  [context release];
67
101
  [super dealloc];
68
- [pool drain];
69
102
  }
70
103
 
71
104
  @end