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
@@ -3,7 +3,7 @@
3
3
  void say_osx_flip_pool() {
4
4
  static say_thread_variable *var = NULL;
5
5
  if (!var) {
6
- var = say_thread_variable_create(NULL);
6
+ var = say_thread_variable_create();
7
7
  }
8
8
 
9
9
  NSAutoreleasePool *pool = say_thread_variable_get(var);
@@ -59,7 +59,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev);
59
59
  if (!(self = [super init]))
60
60
  return nil;
61
61
 
62
- events = say_array_create(sizeof(say_event), NULL, NULL);
62
+ mo_array_init(&events, sizeof(say_event));
63
63
  return self;
64
64
  }
65
65
 
@@ -67,11 +67,6 @@ static uint8_t say_osx_convert_mod(NSEvent *ev);
67
67
  width:(size_t)w
68
68
  height:(size_t)h
69
69
  style:(uint8_t)style {
70
- if ([NSThread currentThread] != [NSThread mainThread]) {
71
- say_error_set("can't create window outside main thread");
72
- return NO;
73
- }
74
-
75
70
  say_osx_setup_process();
76
71
 
77
72
  NSRect rect = NSMakeRect(0, 0, w, h);
@@ -174,11 +169,9 @@ static uint8_t say_osx_convert_mod(NSEvent *ev);
174
169
 
175
170
  bitsPerPixel:0];
176
171
 
177
-
178
- say_color *buf = say_image_get_buffer(img);
179
172
  for (size_t y = 0; y < h; y++) {
180
173
  for (size_t x = 0; x < w; x++) {
181
- say_color col = buf[x + y * w];
174
+ say_color col = say_image_get(img, x, y);
182
175
  NSUInteger pixel[] = {col.r, col.g, col.b, col.a};
183
176
 
184
177
  [rep setPixel:pixel atX:x y:y];
@@ -226,7 +219,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev);
226
219
  say_event ev;
227
220
  ev.type = SAY_EVENT_RESIZE;
228
221
  ev.ev.resize.size = say_make_vector2(w, h);
229
- say_array_push(events, &ev);
222
+ mo_array_push(&events, &ev);
230
223
  }
231
224
  else {
232
225
  NSRect frame = view.frame;
@@ -243,10 +236,12 @@ static uint8_t say_osx_convert_mod(NSEvent *ev);
243
236
 
244
237
  - (void)close {
245
238
  if (window) {
246
- allow_close = YES;
239
+ allow_close = YES;
247
240
  [window close];
248
241
  [window release];
249
242
  window = nil;
243
+
244
+ mo_array_resize(&events, 0);
250
245
  }
251
246
  }
252
247
 
@@ -255,7 +250,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev);
255
250
 
256
251
  [self close];
257
252
  [view release];
258
- say_array_free(events);
253
+ mo_array_release(&events);
259
254
  [super dealloc];
260
255
 
261
256
  say_osx_flip_pool();
@@ -319,9 +314,9 @@ static NSEvent *say_osx_get_event(bool patient) {
319
314
  }
320
315
  [pool drain];
321
316
 
322
- if (say_array_get_size(events) != 0) {
323
- *ev = *(say_event*)say_array_get(events, 0);
324
- say_array_delete(events, 0);
317
+ if (events.size != 0) {
318
+ *ev = mo_array_get_as(&events, 0, say_event);
319
+ mo_array_delete(&events, 0);
325
320
 
326
321
  return YES;
327
322
  }
@@ -336,14 +331,14 @@ static NSEvent *say_osx_get_event(bool patient) {
336
331
 
337
332
  NSAutoreleasePool *pool = [NSAutoreleasePool new];
338
333
 
339
- while (say_array_get_size(events) == 0 && (nsev = say_osx_get_event(true))) {
334
+ while (events.size == 0 && (nsev = say_osx_get_event(true))) {
340
335
  [NSApp sendEvent:nsev];
341
336
  }
342
337
 
343
338
  [pool drain];
344
339
 
345
- *ev = *(say_event*)say_array_get(events, 0);
346
- say_array_delete(events, 0);
340
+ *ev = mo_array_get_as(&events, 0, say_event);
341
+ mo_array_delete(&events, 0);
347
342
  }
348
343
 
349
344
  static say_key say_osx_convert_key(NSEvent *ev) {
@@ -480,7 +475,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
480
475
  ev.ev.key.mod = say_osx_convert_mod(nsev);
481
476
  ev.ev.key.native_code = nsev.keyCode;
482
477
 
483
- say_array_push(events, &ev);
478
+ mo_array_push(&events, &ev);
484
479
  }
485
480
 
486
481
  NSText *text = [window fieldEditor:YES forObject:self];
@@ -491,7 +486,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
491
486
  ev.type = SAY_EVENT_TEXT_ENTERED;
492
487
  ev.ev.text.text = [text.string characterAtIndex:0];
493
488
 
494
- say_array_push(events, &ev);
489
+ mo_array_push(&events, &ev);
495
490
 
496
491
  text.string = @"";
497
492
  }
@@ -505,7 +500,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
505
500
  ev.ev.key.mod = say_osx_convert_mod(nsev);
506
501
  ev.ev.key.native_code = nsev.keyCode;
507
502
 
508
- say_array_push(events, &ev);
503
+ mo_array_push(&events, &ev);
509
504
  }
510
505
 
511
506
  - (void)submitFlagChange:(uint8_t)mod forKey:(say_key)key
@@ -517,7 +512,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
517
512
  ev.ev.key.mod = mod;
518
513
  ev.ev.key.native_code = 0;
519
514
 
520
- say_array_push(events, &ev);
515
+ mo_array_push(&events, &ev);
521
516
  }
522
517
 
523
518
  - (void)flagsChanged:(NSEvent*)nsev {
@@ -578,7 +573,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
578
573
  ev.type = SAY_EVENT_BUTTON_PRESS;
579
574
  ev.ev.button.pos = [self convertPoint:nsev.locationInWindow];
580
575
  ev.ev.button.button = SAY_BUTTON_LEFT;
581
- say_array_push(events, &ev);
576
+ mo_array_push(&events, &ev);
582
577
  }
583
578
 
584
579
  - (void)ownMouseUp:(NSEvent*)nsev {
@@ -586,7 +581,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
586
581
  ev.type = SAY_EVENT_BUTTON_RELEASE;
587
582
  ev.ev.button.pos = [self convertPoint:nsev.locationInWindow];
588
583
  ev.ev.button.button = SAY_BUTTON_LEFT;
589
- say_array_push(events, &ev);
584
+ mo_array_push(&events, &ev);
590
585
  }
591
586
 
592
587
  - (void)ownRightMouseDown:(NSEvent*)nsev {
@@ -594,7 +589,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
594
589
  ev.type = SAY_EVENT_BUTTON_PRESS;
595
590
  ev.ev.button.pos = [self convertPoint:nsev.locationInWindow];
596
591
  ev.ev.button.button = SAY_BUTTON_RIGHT;
597
- say_array_push(events, &ev);
592
+ mo_array_push(&events, &ev);
598
593
  }
599
594
 
600
595
  - (void)ownRightMouseUp:(NSEvent*)nsev {
@@ -602,7 +597,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
602
597
  ev.type = SAY_EVENT_BUTTON_RELEASE;
603
598
  ev.ev.button.pos = [self convertPoint:nsev.locationInWindow];
604
599
  ev.ev.button.button = SAY_BUTTON_RIGHT;
605
- say_array_push(events, &ev);
600
+ mo_array_push(&events, &ev);
606
601
  }
607
602
 
608
603
  /* Assume other mouse button will be middle. */
@@ -611,7 +606,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
611
606
  ev.type = SAY_EVENT_BUTTON_PRESS;
612
607
  ev.ev.button.pos = [self convertPoint:nsev.locationInWindow];
613
608
  ev.ev.button.button = SAY_BUTTON_MIDDLE;
614
- say_array_push(events, &ev);
609
+ mo_array_push(&events, &ev);
615
610
  }
616
611
 
617
612
  - (void)ownOtherMouseUp:(NSEvent*)nsev {
@@ -619,26 +614,26 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
619
614
  ev.type = SAY_EVENT_BUTTON_RELEASE;
620
615
  ev.ev.button.pos = [self convertPoint:nsev.locationInWindow];
621
616
  ev.ev.button.button = SAY_BUTTON_MIDDLE;
622
- say_array_push(events, &ev);
617
+ mo_array_push(&events, &ev);
623
618
  }
624
619
 
625
620
  - (void)mouseMoved:(NSEvent*)nsev {
626
621
  say_event ev;
627
622
  ev.type = SAY_EVENT_MOUSE_MOTION;
628
623
  ev.ev.motion.pos = [self convertPoint:nsev.locationInWindow];
629
- say_array_push(events, &ev);
624
+ mo_array_push(&events, &ev);
630
625
  }
631
626
 
632
627
  - (void)mouseEntered:(NSEvent*)nsev {
633
628
  say_event ev;
634
629
  ev.type = SAY_EVENT_MOUSE_ENTERED;
635
- say_array_push(events, &ev);
630
+ mo_array_push(&events, &ev);
636
631
  }
637
632
 
638
633
  - (void)mouseExited:(NSEvent*)nsev {
639
634
  say_event ev;
640
635
  ev.type = SAY_EVENT_MOUSE_LEFT;
641
- say_array_push(events, &ev);
636
+ mo_array_push(&events, &ev);
642
637
  }
643
638
 
644
639
  - (void)ownScrollWheel:(NSEvent*)nsev {
@@ -649,7 +644,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
649
644
  ev.type = SAY_EVENT_WHEEL_MOTION;
650
645
  ev.ev.wheel.pos = [self convertPoint:nsev.locationInWindow];
651
646
  ev.ev.wheel.delta = nsev.deltaY;
652
- say_array_push(events, &ev);
647
+ mo_array_push(&events, &ev);
653
648
  }
654
649
 
655
650
  /*
@@ -659,7 +654,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
659
654
  - (BOOL)windowShouldClose:(id)sender {
660
655
  say_event ev;
661
656
  ev.type = SAY_EVENT_QUIT;
662
- say_array_push(events, &ev);
657
+ mo_array_push(&events, &ev);
663
658
 
664
659
  if (allow_close) {
665
660
  allow_close = NO;
@@ -672,13 +667,13 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
672
667
  - (void)windowDidBecomeKey:(NSNotification*)not {
673
668
  say_event ev;
674
669
  ev.type = SAY_EVENT_FOCUS_GAIN;
675
- say_array_push(events, &ev);
670
+ mo_array_push(&events, &ev);
676
671
  }
677
672
 
678
673
  - (void)windowDidResignKey:(NSNotification*)not {
679
674
  say_event ev;
680
675
  ev.type = SAY_EVENT_FOCUS_LOSS;
681
- say_array_push(events, &ev);
676
+ mo_array_push(&events, &ev);
682
677
  }
683
678
 
684
679
  - (void)windowDidResize:(NSNotification*)not {
@@ -689,7 +684,7 @@ static uint8_t say_osx_convert_mod(NSEvent *ev) {
689
684
  say_event ev;
690
685
  ev.type = SAY_EVENT_RESIZE;
691
686
  ev.ev.resize.size = say_make_vector2(size.width, size.height);
692
- say_array_push(events, &ev);
687
+ mo_array_push(&events, &ev);
693
688
  }
694
689
 
695
690
  [view removeTrackingRect:track];
@@ -0,0 +1,163 @@
1
+ #include "say.h"
2
+
3
+ static say_context *say_pack_pbo_last_context = NULL;
4
+ static GLuint say_pack_pbo = 0;
5
+
6
+ static void say_pack_pbo_make_current(GLuint pbo) {
7
+ say_context *context = say_context_current();
8
+ if (say_pack_pbo_last_context != context ||
9
+ pbo != say_pack_pbo) {
10
+ say_pack_pbo = pbo;
11
+ say_pack_pbo_last_context = context;
12
+
13
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
14
+ }
15
+ }
16
+
17
+ static say_context *say_unpack_pbo_last_context = NULL;
18
+ static GLuint say_unpack_pbo = 0;
19
+
20
+ static void say_unpack_pbo_make_current(GLuint pbo) {
21
+ say_context *context = say_context_current();
22
+ if (say_unpack_pbo_last_context != context ||
23
+ pbo != say_unpack_pbo) {
24
+ say_unpack_pbo = pbo;
25
+ say_unpack_pbo_last_context = context;
26
+
27
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
28
+ }
29
+ }
30
+
31
+ static void say_pbo_will_delete(GLuint pbo) {
32
+ if (say_pack_pbo == pbo) say_pack_pbo = 0;
33
+ if (say_unpack_pbo == pbo) say_unpack_pbo = 0;
34
+ }
35
+
36
+ bool say_pixel_bus_is_available() {
37
+ say_context_ensure();
38
+ return GLEW_ARB_pixel_buffer_object ||
39
+ GLEW_VERSION_2_1;
40
+ }
41
+
42
+ say_pixel_bus *say_pixel_bus_create(GLenum mode) {
43
+ say_context_ensure();
44
+
45
+ say_pixel_bus *bus = malloc(sizeof(say_pixel_bus));
46
+
47
+ glGenBuffers(1, &bus->pbo);
48
+
49
+ bus->size = 1024;
50
+ bus->mode = mode;
51
+
52
+ say_pixel_bus_bind_pack(bus);
53
+ glBufferData(GL_PIXEL_PACK_BUFFER, 1024 * sizeof(say_color), NULL,
54
+ mode);
55
+
56
+ return bus;
57
+ }
58
+
59
+ void say_pixel_bus_free(say_pixel_bus *bus) {
60
+ say_context_ensure();
61
+ say_pbo_will_delete(bus->pbo);
62
+ glDeleteBuffers(1, &bus->pbo);
63
+ free(bus);
64
+ }
65
+
66
+ size_t say_pixel_bus_pull_image(say_pixel_bus *bus,
67
+ say_image *img, size_t offset) {
68
+ say_image_bind(img);
69
+ say_pixel_bus_bind_pack(bus);
70
+
71
+ glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE,
72
+ (void*)(offset * sizeof(say_color)));
73
+ return offset + say_image_get_width(img) * say_image_get_height(img);
74
+ }
75
+
76
+ size_t say_pixel_bus_pull_target(say_pixel_bus *bus,
77
+ say_target *target, size_t offset,
78
+ size_t x, size_t y, size_t w, size_t h) {
79
+ if (!say_target_make_current(target))
80
+ return offset + w * h;
81
+
82
+ say_pixel_bus_bind_pack(bus);
83
+
84
+ glReadPixels(x, target->size.y - y - h, w, h, GL_RGBA,
85
+ GL_UNSIGNED_BYTE, (void*)(offset * sizeof(say_color)));
86
+ return offset + w * h;
87
+ }
88
+
89
+ void say_pixel_bus_push_image(say_pixel_bus *bus,
90
+ say_image *img, size_t offset,
91
+ size_t x, size_t y, size_t w, size_t h) {
92
+ say_image_bind(img);
93
+ say_pixel_bus_bind_unpack(bus);
94
+
95
+ glTexSubImage2D(GL_TEXTURE_2D, 0,
96
+ x, y, w, h,
97
+ GL_RGBA, GL_UNSIGNED_BYTE,
98
+ (void*)(offset * sizeof(say_color)));
99
+ say_image_mark_out_of_date(img);
100
+ }
101
+
102
+ void say_pixel_bus_bind_pack(say_pixel_bus *bus) {
103
+ say_context_ensure();
104
+ say_pack_pbo_make_current(bus->pbo);
105
+ }
106
+
107
+ void say_pixel_bus_bind_unpack(say_pixel_bus *bus) {
108
+ say_context_ensure();
109
+ say_unpack_pbo_make_current(bus->pbo);
110
+ }
111
+
112
+ void say_pixel_bus_unbind_pack() {
113
+ if (say_pixel_bus_is_available()) say_pack_pbo_make_current(0);
114
+ }
115
+
116
+ void say_pixel_bus_unbind_unpack() {
117
+ if (say_pixel_bus_is_available()) say_unpack_pbo_make_current(0);
118
+ }
119
+
120
+ void say_pixel_bus_bind(say_pixel_bus *bus) {
121
+ say_pixel_bus_bind_pack(bus);
122
+ say_pixel_bus_bind_unpack(bus);
123
+ }
124
+
125
+ void say_pixel_bus_unbind() {
126
+ say_pixel_bus_unbind_pack();
127
+ say_pixel_bus_unbind_unpack();
128
+ }
129
+
130
+ void say_pixel_bus_resize(say_pixel_bus *bus, size_t new_size) {
131
+ /* This is slow, so better not go through this for no reason. */
132
+ if (bus->size == new_size) return;
133
+
134
+ say_pixel_bus_bind_pack(bus);
135
+
136
+ void *buffer = malloc(sizeof(say_color) * new_size);
137
+ glGetBufferSubData(GL_PIXEL_PACK_BUFFER, 0, new_size, buffer);
138
+
139
+ glBufferData(GL_PIXEL_PACK_BUFFER, new_size * sizeof(say_color),
140
+ buffer, bus->mode);
141
+
142
+ free(buffer);
143
+
144
+ bus->size = new_size;
145
+ }
146
+
147
+ void say_pixel_bus_resize_fast(say_pixel_bus *bus, size_t new_size) {
148
+ if (bus->size == new_size) return;
149
+
150
+ say_pixel_bus_bind_pack(bus);
151
+ glBufferData(GL_PIXEL_PACK_BUFFER, new_size * sizeof(say_color), NULL,
152
+ bus->mode);
153
+
154
+ bus->size = new_size;
155
+ }
156
+
157
+ size_t say_pixel_bus_get_size(say_pixel_bus *bus) {
158
+ return bus->size;
159
+ }
160
+
161
+ GLuint say_pixel_bus_get_pbo(say_pixel_bus *bus) {
162
+ return bus->pbo;
163
+ }
@@ -0,0 +1,44 @@
1
+ #ifndef SAY_PIXEL_BUS_H_
2
+ #define SAY_PIXEL_BUS_H_
3
+
4
+ #include "say_target.h"
5
+ #include "say_image.h"
6
+
7
+ typedef struct say_pixel_bus {
8
+ GLuint pbo;
9
+ size_t size;
10
+ GLenum mode;
11
+ } say_pixel_bus;
12
+
13
+ bool say_pixel_bus_is_available();
14
+
15
+ say_pixel_bus *say_pixel_bus_create(GLenum mode);
16
+ void say_pixel_bus_free(say_pixel_bus *bus);
17
+
18
+ size_t say_pixel_bus_pull_image(say_pixel_bus *bus,
19
+ say_image *img, size_t offset);
20
+ size_t say_pixel_bus_pull_target(say_pixel_bus *bus,
21
+ say_target *target, size_t offset,
22
+ size_t x, size_t y, size_t w, size_t h);
23
+
24
+ void say_pixel_bus_push_image(say_pixel_bus *bus,
25
+ say_image *img, size_t offset,
26
+ size_t x, size_t y, size_t w, size_t h);
27
+
28
+ void say_pixel_bus_bind_pack(say_pixel_bus *bus);
29
+ void say_pixel_bus_bind_unpack(say_pixel_bus *bus);
30
+
31
+ void say_pixel_bus_unbind_pack();
32
+ void say_pixel_bus_unbind_unpack();
33
+
34
+ void say_pixel_bus_bind(say_pixel_bus *bus);
35
+ void say_pixel_bus_unbind();
36
+
37
+ void say_pixel_bus_resize(say_pixel_bus *bus, size_t new_size);
38
+ void say_pixel_bus_resize_fast(say_pixel_bus *bus, size_t new_size);
39
+
40
+ size_t say_pixel_bus_get_size(say_pixel_bus *bus);
41
+
42
+ GLuint say_pixel_bus_get_pbo(say_pixel_bus *bus);
43
+
44
+ #endif