ray 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -9,6 +9,8 @@
9
9
 
10
10
  #include <GL/glx.h>
11
11
 
12
+ #include "mo.h"
13
+
12
14
  typedef struct say_x11_window {
13
15
  Display *dis;
14
16
  Window win;
@@ -17,7 +19,7 @@ typedef struct say_x11_window {
17
19
  XVisualInfo *vi;
18
20
  GLXFBConfig config;
19
21
 
20
- struct say_array *events;
22
+ mo_array events;
21
23
 
22
24
  XIM im;
23
25
  XIC ic;
@@ -1,22 +1,78 @@
1
1
  #include "say.h"
2
2
 
3
+ #ifdef HAVE_GL_GLXEXT_H
4
+ # include <GL/glxext.h>
5
+ #else
6
+ # define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
7
+ # define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
8
+ # define GLX_CONTEXT_FLAGS_ARB 0x2094
9
+ # define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
10
+
11
+ # define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
12
+ # define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
13
+
14
+ # define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001
15
+ #endif
16
+
17
+ typedef GLXContext (*say_glx_create_context)(Display *dpy,
18
+ GLXFBConfig config,
19
+ GLXContext share_context,
20
+ Bool direct,
21
+ const int *attrib_list);
22
+
23
+ static say_glx_create_context glXCreateContextAttribs = NULL;
24
+
3
25
  say_imp_context say_imp_context_create() {
4
- return say_imp_context_create_shared(NULL);
26
+ return say_imp_context_create_shared(NULL);
27
+ }
28
+
29
+ static GLXContext say_x11_do_create_context(Display *dis,
30
+ GLXFBConfig conf,
31
+ GLXContext share) {
32
+ glXCreateContextAttribs = (say_glx_create_context)
33
+ glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB");
34
+
35
+ say_context_config *say_conf = say_context_get_config();
36
+ size_t major = say_conf->major_version, minor = say_conf->minor_version;
37
+
38
+ if (glXCreateContextAttribs) {
39
+ GLint attribs[] = {
40
+ GLX_CONTEXT_MAJOR_VERSION_ARB, major,
41
+ GLX_CONTEXT_MINOR_VERSION_ARB, minor,
42
+ GLX_CONTEXT_FLAGS_ARB, say_conf->debug ? GLX_CONTEXT_DEBUG_BIT_ARB : 0,
43
+ GLX_CONTEXT_PROFILE_MASK_ARB, say_conf->core_profile ?
44
+ GLX_CONTEXT_CORE_PROFILE_BIT_ARB :
45
+ GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
46
+ None
47
+ };
48
+
49
+ GLXContext ctxt = glXCreateContextAttribs(dis, conf, share, true,
50
+ attribs);
51
+
52
+ if (ctxt)
53
+ return ctxt;
54
+ }
55
+
56
+ return glXCreateNewContext(dis, conf, GLX_RGBA_TYPE, share, True);
5
57
  }
6
58
 
7
59
  say_imp_context say_imp_context_create_shared(say_imp_context shared) {
8
60
  say_x11_context *context = malloc(sizeof(say_x11_context));
9
61
 
62
+ context->should_free_window = true;
63
+
10
64
  context->dis = XOpenDisplay(NULL);
11
65
 
12
66
  int screen = DefaultScreen(context->dis);
13
67
 
14
- static int visual_attribs[] = {
68
+ say_context_config *say_conf = say_context_get_config();
69
+ int visual_attribs[] = {
15
70
  GLX_RED_SIZE, 8,
16
71
  GLX_GREEN_SIZE, 8,
17
72
  GLX_BLUE_SIZE, 8,
18
73
  GLX_ALPHA_SIZE, 8,
19
- GLX_DEPTH_SIZE, 24,
74
+ GLX_DEPTH_SIZE, say_conf->depth_size,
75
+ GLX_STENCIL_SIZE, say_conf->stencil_size,
20
76
  GLX_DOUBLEBUFFER, True,
21
77
  None
22
78
  };
@@ -44,12 +100,11 @@ say_imp_context say_imp_context_create_shared(say_imp_context shared) {
44
100
  InputOutput,
45
101
  vi->visual,
46
102
  CWBorderPixel|CWColormap, &swa);
47
-
48
103
  XFree(vi);
49
104
 
50
105
  GLXContext glx_shared = shared ? shared->context : NULL;
51
- context->context = glXCreateNewContext(context->dis, config, GLX_RGBA_TYPE,
52
- glx_shared, True);
106
+ context->context = say_x11_do_create_context(context->dis, config,
107
+ glx_shared);
53
108
 
54
109
  return context;
55
110
  }
@@ -63,8 +118,8 @@ say_imp_context say_imp_context_create_for_window(say_imp_context shared,
63
118
 
64
119
  context->should_free_window = 0;
65
120
 
66
- context->context = glXCreateNewContext(window->dis, window->config,
67
- GLX_RGBA_TYPE, shared->context, True);
121
+ context->context = say_x11_do_create_context(window->dis, window->config,
122
+ shared->context);
68
123
 
69
124
  return context;
70
125
  }
@@ -90,7 +145,6 @@ void say_imp_context_make_current(say_imp_context context) {
90
145
  }
91
146
 
92
147
  void say_imp_context_update(say_imp_context context) {
93
- if (context->win)
94
- glXSwapBuffers(context->dis, context->win);
148
+ glXSwapBuffers(context->dis, context->win);
95
149
  }
96
150
 
@@ -129,13 +129,13 @@ say_imp_window say_imp_window_create() {
129
129
  win->hidden_cursor = None;
130
130
  win->old_video_mode = -1;
131
131
 
132
- win->events = say_array_create(sizeof(say_event), NULL, NULL);
132
+ mo_array_init(&win->events, sizeof(say_event));
133
133
 
134
134
  return win;
135
135
  }
136
136
 
137
137
  void say_imp_window_free(say_imp_window win) {
138
- say_array_free(win->events);
138
+ mo_array_release(&win->events);
139
139
  free(win);
140
140
  }
141
141
 
@@ -298,7 +298,7 @@ bool say_imp_window_open(say_imp_window win, const char *title,
298
298
  }
299
299
 
300
300
  void say_imp_window_close(say_imp_window win) {
301
- say_array_resize(win->events, 0);
301
+ mo_array_resize(&win->events, 0);
302
302
 
303
303
  #ifdef HAVE_XRANDR
304
304
  if (win->dis && win->old_video_mode >= 0) {
@@ -375,10 +375,13 @@ bool say_imp_window_set_icon(say_imp_window win, struct say_image *icon) {
375
375
 
376
376
  /* Convert image to BGRA */
377
377
 
378
- say_color *orig_buf = say_image_get_buffer(icon);
379
- long *pixels = malloc(sizeof(long) * (2 + (icon->width * icon->height)));
378
+ say_color *orig_buf = say_flip_color_buffer_copy(say_image_get_buffer(icon),
379
+ say_image_get_width(icon),
380
+ say_image_get_height(icon));
380
381
 
381
- if (!pixels) {
382
+ long *pixels = malloc(sizeof(long) * (2 + (icon->width * icon->height)));
383
+
384
+ if (!(pixels && orig_buf)) {
382
385
  say_error_set("could not allocate icon buffer");
383
386
  return false;
384
387
  }
@@ -399,6 +402,8 @@ bool say_imp_window_set_icon(say_imp_window win, struct say_image *icon) {
399
402
  buf++;
400
403
  }
401
404
 
405
+ free(orig_buf);
406
+
402
407
  /* Set _NET_WM_ICON */
403
408
 
404
409
  Atom icon_atom = XInternAtom(win->dis, "_NET_WM_ICON", false);
@@ -695,7 +700,7 @@ static int say_x11_window_parse_event(say_x11_window *win, say_event *ev,
695
700
  ev.type = SAY_EVENT_TEXT_ENTERED;
696
701
  ev.ev.text.text = character;
697
702
 
698
- say_array_push(win->events, &ev);
703
+ mo_array_push(&win->events, &ev);
699
704
  }
700
705
  }
701
706
  else
@@ -711,14 +716,14 @@ static int say_x11_window_parse_event(say_x11_window *win, say_event *ev,
711
716
  ev.type = SAY_EVENT_TEXT_ENTERED;
712
717
  ev.ev.text.text = (uint32_t)key_buffer[0];
713
718
 
714
- say_array_push(win->events, &ev);
719
+ mo_array_push(&win->events, &ev);
715
720
  }
716
721
  }
717
722
  }
718
723
 
719
- if (ev->type == SAY_EVENT_NONE && say_array_get_size(win->events) != 0) {
720
- *ev = *(say_event*)say_array_get(win->events, 0);
721
- say_array_delete(win->events, 0);
724
+ if (ev->type == SAY_EVENT_NONE && win->events.size != 0) {
725
+ *ev = mo_array_get_as(&win->events, 0, say_event);
726
+ mo_array_delete(&win->events, 0);
722
727
 
723
728
  return 1;
724
729
  }
@@ -775,9 +780,9 @@ static int say_x11_window_parse_event(say_x11_window *win, say_event *ev,
775
780
 
776
781
  bool say_imp_window_poll_event(say_imp_window win, struct say_event *ev,
777
782
  struct say_input *input) {
778
- if (say_array_get_size(win->events) != 0) {
779
- *ev = *(say_event*)say_array_get(win->events, 0);
780
- say_array_delete(win->events, 0);
783
+ if (win->events.size != 0) {
784
+ *ev = mo_array_get_as(&win->events, 0, say_event);
785
+ mo_array_delete(&win->events, 0);
781
786
 
782
787
  return 1;
783
788
  }
@@ -798,9 +803,9 @@ bool say_imp_window_poll_event(say_imp_window win, struct say_event *ev,
798
803
 
799
804
  void say_imp_window_wait_event(say_imp_window win, struct say_event *ev,
800
805
  struct say_input *input) {
801
- if (say_array_get_size(win->events) != 0) {
802
- *ev = *(say_event*)say_array_get(win->events, 0);
803
- say_array_delete(win->events, 0);
806
+ if (win->events.size != 0) {
807
+ *ev = mo_array_get_as(&win->events, 0, say_event);
808
+ mo_array_delete(&win->events, 0);
804
809
 
805
810
  return;
806
811
  }
@@ -158,6 +158,14 @@ VALUE ray_shader_bind(VALUE self) {
158
158
  return Qnil;
159
159
  }
160
160
 
161
+ /*
162
+ * @return [Integer] The OpenGL program id
163
+ */
164
+ static
165
+ VALUE ray_shader_program(VALUE self) {
166
+ return NUM2ULONG(say_shader_get_program(ray_rb2shader(self)));
167
+ }
168
+
161
169
  static
162
170
  VALUE ray_shader_set_vector2(VALUE self, VALUE loc, VALUE val) {
163
171
  rb_check_frozen(self);
@@ -299,4 +307,5 @@ void Init_ray_shader() {
299
307
  rb_define_method(ray_cShader, "set_bool", ray_shader_set_bool, 2);
300
308
 
301
309
  rb_define_method(ray_cShader, "bind", ray_shader_bind, 0);
310
+ rb_define_method(ray_cShader, "program", ray_shader_program, 0);
302
311
  }
@@ -16,11 +16,17 @@ say_sprite *ray_rb2sprite(VALUE obj) {
16
16
 
17
17
  VALUE ray_sprite_alloc(VALUE self) {
18
18
  say_sprite *sprite = say_sprite_create();
19
- return Data_Wrap_Struct(self, NULL, say_sprite_free, sprite);
19
+ VALUE rb = Data_Wrap_Struct(self, NULL, say_sprite_free, sprite);
20
+
21
+ say_drawable_set_shader_proc(sprite->drawable, ray_drawable_shader_proc);
22
+ say_drawable_set_other_data(sprite->drawable, (void*)rb);
23
+
24
+ return rb;
20
25
  }
21
26
 
22
27
  VALUE ray_sprite_init_copy(VALUE self, VALUE orig) {
23
28
  rb_iv_set(self, "@image", rb_iv_get(orig, "@image"));
29
+ ray_drawable_copy_attr(self, orig);
24
30
  say_sprite_copy(ray_rb2sprite(self), ray_rb2sprite(orig));
25
31
  return self;
26
32
  }
@@ -18,19 +18,28 @@ say_target *ray_rb2target(VALUE obj) {
18
18
  }
19
19
 
20
20
  /*
21
- @return [Ray::Vector2] Size of the target, in pixels.
22
- */
21
+ * @return [Ray::Vector2] Size of the target, in pixels.
22
+ */
23
23
  static
24
24
  VALUE ray_target_size(VALUE self) {
25
25
  return ray_vector2_to_rb(say_target_get_size(ray_rb2target(self)));
26
26
  }
27
27
 
28
- /* @return [Ray::View] View currently used */
28
+ /* @see view= */
29
29
  static
30
30
  VALUE ray_target_view(VALUE self) {
31
31
  return ray_view2rb(say_target_get_view(ray_rb2target(self)));
32
32
  }
33
33
 
34
+ /*
35
+ * @overload view=(view)
36
+ * Sets the view used by the target
37
+ *
38
+ * Notice the view returned by {#view} is a copy of the view used internally.
39
+ *
40
+ * @param [Ray::View] view New view
41
+ * @see Ray::View
42
+ */
34
43
  static
35
44
  VALUE ray_target_set_view(VALUE self, VALUE val) {
36
45
  rb_check_frozen(self);
@@ -39,28 +48,51 @@ VALUE ray_target_set_view(VALUE self, VALUE val) {
39
48
  }
40
49
 
41
50
 
42
- /* @return [Ray::View] Default view of the target */
51
+ /*
52
+ * Default view of the target
53
+ *
54
+ * The default view is made so that no scaling will be performed. It has the
55
+ * following properties:
56
+ *
57
+ * 1. +size+ is the size of the target;
58
+ * 2. +center+ is the center of the target (half of the target);
59
+ * 3. +viewport+ is the whole target (that is, +[0, 0, 1, 1]+).
60
+ *
61
+ * @return [Ray::View] Default view of the target
62
+ */
43
63
  static
44
64
  VALUE ray_target_default_view(VALUE self) {
45
65
  say_view *view = say_target_get_default_view(ray_rb2target(self));
46
- return Data_Wrap_Struct(rb_path2class("Ray::View"), NULL, say_view_free, view);
66
+ return Data_Wrap_Struct(rb_path2class("Ray::View"), NULL, say_view_free,
67
+ view);
47
68
  }
48
69
 
70
+ /*
71
+ * Low-level access to the shader. {#shader} will cache this.
72
+ * @return [Ray::Shader] The target's shader
73
+ */
49
74
  static
50
75
  VALUE ray_target_shader(VALUE self) {
51
76
  return ray_shader2rb(say_target_get_shader(ray_rb2target(self)), self);
52
77
  }
53
78
 
54
- /* @return [Ray::Rect] Part of the target that's used by the view */
79
+ /*
80
+ * Clipping rectangle when using the current view
81
+ * @return [Ray::Rect] Part of the target that's used by the view
82
+ *
83
+ * @see Ray::View.clip
84
+ */
55
85
  static
56
86
  VALUE ray_target_clip(VALUE self) {
57
87
  return ray_rect2rb(say_target_get_clip(ray_rb2target(self)));
58
88
  }
59
89
 
60
90
  /*
61
- @overload viewport_for(rect)
62
- @param [Ray::Rect] rect Rect in pixel
63
- @return [Ray::Rect] Viewport to set in the view
91
+ * @overload viewport_for(rect)
92
+ * Viewport for a view to make it draw on a given rect
93
+ *
94
+ * @param [Ray::Rect] rect Rect in pixel
95
+ * @return [Ray::Rect] Viewport to set in the view
64
96
  */
65
97
  static
66
98
  VALUE ray_target_viewport_for(VALUE self, VALUE rect) {
@@ -69,12 +101,15 @@ VALUE ray_target_viewport_for(VALUE self, VALUE rect) {
69
101
  }
70
102
 
71
103
  /*
72
- Makes a target become the current one.
73
- Not useful unless using OpenGL directly.
74
-
75
- @raise If a context could not be created or made current. Would often mean the
76
- target was not initialized properly (e.g. window is not open)
77
- */
104
+ * Makes a target become the current one
105
+ *
106
+ * This method is only used when using low-level OpenGL access. Calling {#draw}
107
+ * will cause this method to be called anyway (and custom drawables also allow
108
+ * OpenGL calls)
109
+ *
110
+ * @raise If a context could not be created or made current. This Would often
111
+ * mean the target was not initialized properly (e.g. window is not open)
112
+ */
78
113
  static
79
114
  VALUE ray_target_make_current(VALUE self) {
80
115
  if (!say_target_make_current(ray_rb2target(self)))
@@ -83,12 +118,13 @@ VALUE ray_target_make_current(VALUE self) {
83
118
  }
84
119
 
85
120
  /*
86
- @overload clear(color)
87
- Clears the target in a given color. Should usually be called before drawing
88
- anything in a new frame.
89
-
90
- @param [Ray::Color] color Color to clear the target with.
91
- */
121
+ * @overload clear(color)
122
+ * Clears the target in a given color
123
+ *
124
+ * This method should usually be called before performing drawing.
125
+ *
126
+ * @param [Ray::Color] color Color to clear the target with.
127
+ */
92
128
  static
93
129
  VALUE ray_target_clear(VALUE self, VALUE color) {
94
130
  say_target_clear(ray_rb2target(self), ray_rb2col(color));
@@ -96,10 +132,10 @@ VALUE ray_target_clear(VALUE self, VALUE color) {
96
132
  }
97
133
 
98
134
  /*
99
- @overload draw(obj)
100
- Draws an object on the target.
101
- @param [Ray::Drawable, Ray::BufferRenderer] obj Object to be drawn
102
- */
135
+ * @overload draw(obj)
136
+ * Draws an object on the target
137
+ * @param [Ray::Drawable, Ray::BufferRenderer] obj Object to be drawn
138
+ */
103
139
  static
104
140
  VALUE ray_target_draw(VALUE self, VALUE obj) {
105
141
  if (RAY_IS_A(obj, rb_path2class("Ray::BufferRenderer"))) {
@@ -113,6 +149,11 @@ VALUE ray_target_draw(VALUE self, VALUE obj) {
113
149
 
114
150
  /*
115
151
  * @overload [](x, y)
152
+ * Color of the pixel at a given position
153
+ *
154
+ * This operation is slow. It is much faster to access a rect or the whole
155
+ * image than to read each pixel from that rect.
156
+ *
116
157
  * @param [Integer] x
117
158
  * @param [Integer] y
118
159
  *
@@ -127,7 +168,8 @@ VALUE ray_target_get(VALUE self, VALUE x, VALUE y) {
127
168
 
128
169
  /*
129
170
  * @overload rect(rect)
130
- * @param [Ray::Rect] rect
171
+ * Colors of pixels present in a rect
172
+ * @param [Ray::Rect] rect Rect to read pixels from
131
173
  * @return [Ray::Image] An image containing the pixels of that rect.
132
174
  */
133
175
  static
@@ -146,6 +188,7 @@ VALUE ray_target_rect(VALUE self, VALUE rect) {
146
188
  }
147
189
 
148
190
  /*
191
+ * Colors of all the pixels in the target
149
192
  * @return [Ray::Image] An image containing all the pixels of the target
150
193
  */
151
194
  static
@@ -165,20 +208,29 @@ void Init_ray_target() {
165
208
 
166
209
  rb_define_method(ray_cTarget, "size", ray_target_size, 0);
167
210
 
211
+ /* @group Manipulating views */
168
212
  rb_define_method(ray_cTarget, "view", ray_target_view, 0);
169
213
  rb_define_method(ray_cTarget, "view=", ray_target_set_view, 1);
170
214
  rb_define_method(ray_cTarget, "default_view", ray_target_default_view, 0);
171
215
 
172
- rb_define_private_method(ray_cTarget, "simple_shader", ray_target_shader, 0);
173
-
174
216
  rb_define_method(ray_cTarget, "clip", ray_target_clip, 0);
175
217
  rb_define_method(ray_cTarget, "viewport_for", ray_target_viewport_for, 1);
218
+ /* @endgroup */
219
+
220
+ rb_define_private_method(ray_cTarget, "simple_shader", ray_target_shader, 0);
176
221
 
222
+ /* @group Low-level access */
177
223
  rb_define_method(ray_cTarget, "make_current", ray_target_make_current, 0);
224
+ /* @endgroup */
225
+
226
+ /* @group Drawing */
178
227
  rb_define_method(ray_cTarget, "clear", ray_target_clear, 1);
179
228
  rb_define_method(ray_cTarget, "draw", ray_target_draw, 1);
229
+ /* @endgroup */
180
230
 
231
+ /* @group Pixel-level access */
181
232
  rb_define_method(ray_cTarget, "[]", ray_target_get, 2);
182
233
  rb_define_method(ray_cTarget, "rect", ray_target_rect, 1);
183
234
  rb_define_method(ray_cTarget, "to_image", ray_target_to_image, 0);
235
+ /* @endgroup */
184
236
  }