ashton 0.0.1alpha → 0.0.2alpha

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 (116) hide show
  1. data/LICENSE +21 -21
  2. data/README.md +95 -68
  3. data/Rakefile +41 -23
  4. data/examples/bloom_example.rb +59 -0
  5. data/examples/lighting_example.rb +127 -0
  6. data/examples/media/SmallStar.png +0 -0
  7. data/examples/media/Starfighter.png +0 -0
  8. data/examples/media/simple.png +0 -0
  9. data/examples/noise_example.rb +94 -0
  10. data/examples/outline_example.rb +86 -0
  11. data/examples/particle_emitter_example.rb +114 -0
  12. data/examples/pixelate_example.rb +51 -49
  13. data/examples/pixelated_texture_example.rb +69 -0
  14. data/examples/radial_blur_example.rb +60 -62
  15. data/examples/shader_image_example.rb +74 -41
  16. data/examples/{shockwave2_example.rb → shockwave_example.rb} +74 -75
  17. data/examples/stencil_shader_example.rb +104 -0
  18. data/examples/{framebuffer_example.rb → texture_render_example.rb} +53 -49
  19. data/examples/{tv_screen_and_noise_example.rb → tv_screen_and_static_example.rb} +59 -59
  20. data/ext/ashton/GLee.c +18170 -0
  21. data/ext/ashton/GLee.h +17647 -0
  22. data/ext/ashton/ashton.c +42 -0
  23. data/ext/ashton/ashton.h +31 -0
  24. data/ext/ashton/color.c +45 -0
  25. data/ext/ashton/color.h +25 -0
  26. data/ext/ashton/common.h +41 -0
  27. data/ext/ashton/extconf.rb +42 -0
  28. data/ext/ashton/fast_math.c +30 -0
  29. data/ext/ashton/fast_math.h +30 -0
  30. data/ext/ashton/font.c +8 -0
  31. data/ext/ashton/font.h +16 -0
  32. data/ext/ashton/gosu.c +18 -0
  33. data/ext/ashton/gosu.h +19 -0
  34. data/ext/ashton/image.c +8 -0
  35. data/ext/ashton/image.h +16 -0
  36. data/ext/ashton/particle_emitter.c +788 -0
  37. data/ext/ashton/particle_emitter.h +171 -0
  38. data/ext/ashton/pixel_cache.c +237 -0
  39. data/ext/ashton/pixel_cache.h +58 -0
  40. data/ext/ashton/shader.c +9 -0
  41. data/ext/ashton/shader.h +16 -0
  42. data/ext/ashton/texture.c +442 -0
  43. data/ext/ashton/texture.h +63 -0
  44. data/ext/ashton/window.c +8 -0
  45. data/ext/ashton/window.h +16 -0
  46. data/lib/ashton.rb +38 -26
  47. data/lib/ashton/1.9/ashton.so +0 -0
  48. data/lib/ashton/gosu_ext/color.rb +24 -11
  49. data/lib/ashton/gosu_ext/font.rb +58 -0
  50. data/lib/ashton/gosu_ext/gosu_module.rb +16 -0
  51. data/lib/ashton/gosu_ext/image.rb +95 -31
  52. data/lib/ashton/gosu_ext/window.rb +78 -35
  53. data/lib/ashton/image_stub.rb +32 -36
  54. data/lib/ashton/lighting/light_source.rb +146 -0
  55. data/lib/ashton/lighting/manager.rb +98 -0
  56. data/lib/ashton/mixins/version_checking.rb +23 -0
  57. data/lib/ashton/particle_emitter.rb +87 -0
  58. data/lib/ashton/pixel_cache.rb +24 -0
  59. data/lib/ashton/shader.rb +353 -35
  60. data/lib/ashton/shaders/bloom.frag +41 -0
  61. data/lib/ashton/shaders/color_inversion.frag +11 -0
  62. data/lib/ashton/{post_process → shaders}/contrast.frag +16 -16
  63. data/lib/ashton/{shader → shaders}/default.frag +22 -19
  64. data/lib/ashton/{shader → shaders}/default.vert +13 -13
  65. data/lib/ashton/shaders/fade.frag +14 -0
  66. data/lib/ashton/shaders/grayscale.frag +15 -0
  67. data/lib/ashton/shaders/include/classicnoise2d.glsl +113 -0
  68. data/lib/ashton/shaders/include/classicnoise3d.glsl +177 -0
  69. data/lib/ashton/shaders/include/classicnoise4d.glsl +302 -0
  70. data/lib/ashton/{include/simplex.glsl → shaders/include/noise2d.glsl} +70 -63
  71. data/lib/ashton/shaders/include/noise3d.glsl +102 -0
  72. data/lib/ashton/shaders/include/noise4d.glsl +128 -0
  73. data/lib/ashton/shaders/include/rand.glsl +5 -0
  74. data/lib/ashton/shaders/lighting/distort.frag +57 -0
  75. data/lib/ashton/shaders/lighting/draw_shadows.frag +60 -0
  76. data/lib/ashton/shaders/lighting/shadow_blur.frag +60 -0
  77. data/lib/ashton/shaders/mezzotint.frag +22 -0
  78. data/lib/ashton/shaders/multitexture2.vert +19 -0
  79. data/lib/ashton/shaders/outline.frag +45 -0
  80. data/lib/ashton/{post_process → shaders}/pixelate.frag +48 -48
  81. data/lib/ashton/shaders/radial_blur.frag +63 -0
  82. data/lib/ashton/shaders/sepia.frag +26 -0
  83. data/lib/ashton/{post_process/shockwave2.frag → shaders/shockwave.frag} +38 -35
  84. data/lib/ashton/shaders/signed_distance_field.frag +80 -0
  85. data/lib/ashton/{post_process/noise.frag → shaders/static.frag} +25 -27
  86. data/lib/ashton/shaders/stencil.frag +27 -0
  87. data/lib/ashton/shaders/tv_screen.frag +23 -0
  88. data/lib/ashton/signed_distance_field.rb +151 -0
  89. data/lib/ashton/texture.rb +186 -0
  90. data/lib/ashton/version.rb +2 -2
  91. data/lib/ashton/window_buffer.rb +16 -0
  92. data/spec/ashton/ashton_spec.rb +22 -0
  93. data/spec/ashton/gosu_ext/color_spec.rb +34 -0
  94. data/spec/ashton/gosu_ext/font_spec.rb +57 -0
  95. data/spec/ashton/gosu_ext/gosu_spec.rb +11 -0
  96. data/spec/ashton/gosu_ext/image_spec.rb +66 -0
  97. data/spec/ashton/gosu_ext/window_spec.rb +71 -0
  98. data/spec/ashton/image_stub_spec.rb +46 -0
  99. data/spec/ashton/particle_emitter_spec.rb +123 -0
  100. data/spec/ashton/pixel_cache_spec.rb +153 -0
  101. data/spec/ashton/shader_spec.rb +152 -0
  102. data/spec/ashton/signed_distance_field_spec.rb +163 -0
  103. data/spec/ashton/texture_spec.rb +347 -0
  104. data/spec/helper.rb +12 -0
  105. metadata +159 -28
  106. data/examples/output/README.txt +0 -1
  107. data/lib/ashton/base_shader.rb +0 -172
  108. data/lib/ashton/framebuffer.rb +0 -183
  109. data/lib/ashton/post_process.rb +0 -83
  110. data/lib/ashton/post_process/default.vert +0 -9
  111. data/lib/ashton/post_process/fade.frag +0 -11
  112. data/lib/ashton/post_process/mezzotint.frag +0 -24
  113. data/lib/ashton/post_process/radial_blur.frag +0 -31
  114. data/lib/ashton/post_process/sepia.frag +0 -19
  115. data/lib/ashton/post_process/shockwave.frag +0 -40
  116. data/lib/ashton/post_process/tv_screen.frag +0 -32
@@ -0,0 +1,63 @@
1
+ /*
2
+ * class Ashton::Texture
3
+ *
4
+ *
5
+ */
6
+
7
+
8
+ #ifndef ASHTON_FRAMEBUFFER_H
9
+ #define ASHTON_FRAMEBUFFER_H
10
+
11
+ #include <math.h>
12
+
13
+ #include "common.h"
14
+ #include "pixel_cache.h"
15
+
16
+ #define DRAW_MODE_ALPHA_BLEND "alpha_blend"
17
+ #define DRAW_MODE_ADD "add"
18
+ #define DRAW_MODE_MULTIPLY "multiply"
19
+ #define DRAW_MODE_REPLACE "replace"
20
+
21
+ typedef struct _texture
22
+ {
23
+ uint width;
24
+ uint height;
25
+
26
+ GLuint fbo_id;
27
+ GLuint id;
28
+
29
+ VALUE rb_cache; // Value of cache for marking purpose.
30
+ } Texture;
31
+
32
+ // Create an 'texture' variable which points to our data.
33
+ #define TEXTURE() \
34
+ Texture* texture; \
35
+ Data_Get_Struct(self, Texture, texture);
36
+
37
+ void Init_Ashton_Texture(VALUE module);
38
+
39
+ // Getters.
40
+ VALUE Ashton_Texture_get_cache(VALUE self);
41
+ VALUE Ashton_Texture_get_width(VALUE self);
42
+ VALUE Ashton_Texture_get_height(VALUE self);
43
+ VALUE Ashton_Texture_get_fbo_id(VALUE self);
44
+ VALUE Ashton_Texture_get_id(VALUE self);
45
+
46
+ // Creation and destruction.
47
+ VALUE Ashton_Texture_init(VALUE self, VALUE width, VALUE height, VALUE blob);
48
+
49
+ // Methods.
50
+ VALUE Ashton_Texture_refresh_cache(VALUE self);
51
+ VALUE Ashton_Texture_get_pixel(VALUE self, VALUE x, VALUE y);
52
+ VALUE Ashton_Texture_get_rgba_array(VALUE self, VALUE x, VALUE y);
53
+ VALUE Ashton_Texture_get_red(VALUE self, VALUE x, VALUE y);
54
+ VALUE Ashton_Texture_get_green(VALUE self, VALUE x, VALUE y);
55
+ VALUE Ashton_Texture_get_blue(VALUE self, VALUE x, VALUE y);
56
+ VALUE Ashton_Texture_get_alpha(VALUE self, VALUE x, VALUE y);
57
+ VALUE Ashton_Texture_is_transparent(VALUE self, VALUE x, VALUE y);
58
+ VALUE Ashton_Texture_to_blob(VALUE self);
59
+ VALUE Ashton_Texture_draw(int argc, VALUE argv[], VALUE self);
60
+ VALUE Ashton_Texture_render(VALUE self);
61
+
62
+ #endif // ASHTON_FRAMEBUFFER_H
63
+
@@ -0,0 +1,8 @@
1
+ #include "window.h"
2
+
3
+ VALUE rb_cWindow;
4
+
5
+ void Init_Gosu_Window(VALUE module)
6
+ {
7
+ rb_cWindow = rb_define_class_under(module, "Window", rb_cObject);
8
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * class Gosu::Window
3
+ *
4
+ *
5
+ */
6
+
7
+
8
+ #ifndef GOSU_WINDOW_H
9
+ #define GOSU_WINDOW_H
10
+
11
+ #include "common.h"
12
+
13
+ void Init_Gosu_Window(VALUE module);
14
+
15
+ #endif // GOSU_WINDOW_H
16
+
data/lib/ashton.rb CHANGED
@@ -1,26 +1,38 @@
1
- require 'opengl'
2
- require 'gosu'
3
-
4
-
5
-
6
- module Ashton
7
- class Error < RuntimeError; end
8
-
9
- class NotSupportedError < Error; end
10
-
11
- class ShaderError < Error; end
12
- class ShaderCompileError < ShaderError; end
13
- class ShaderLinkError < ShaderError; end
14
- class ShaderUniformError < ShaderError; end
15
- class ShaderAttributeError < ShaderError; end
16
- end
17
-
18
- require "ashton/gosu_ext/window"
19
- require "ashton/gosu_ext/image"
20
- require "ashton/gosu_ext/color"
21
-
22
- require "ashton/version"
23
- require "ashton/shader"
24
- require "ashton/post_process"
25
- require "ashton/framebuffer"
26
- require "ashton/image_stub"
1
+ require 'opengl'
2
+ require 'gosu'
3
+
4
+ begin
5
+ RUBY_VERSION =~ /(\d+.\d+)/
6
+ require "ashton/#{$1}/ashton.#{RbConfig::CONFIG['DLEXT']}"
7
+ rescue LoadError
8
+ require "ashton/ashton.#{RbConfig::CONFIG['DLEXT']}"
9
+ end
10
+
11
+ module Ashton
12
+ class Error < StandardError; end
13
+
14
+ class NotSupportedError < Error; end
15
+
16
+ class ShaderError < Error; end
17
+ class ShaderCompileError < ShaderError; end
18
+ class ShaderLinkError < ShaderError; end
19
+ class ShaderUniformError < ShaderError; end
20
+ class ShaderAttributeError < ShaderError; end
21
+ class ShaderLoadError < ShaderError; end
22
+ end
23
+
24
+ require_relative "ashton/gosu_ext/gosu_module"
25
+
26
+ require_relative "ashton/mixins/version_checking"
27
+
28
+ require_relative "ashton/version"
29
+ require_relative "ashton/shader"
30
+ require_relative "ashton/signed_distance_field"
31
+ require_relative "ashton/texture"
32
+ require_relative "ashton/window_buffer"
33
+ require_relative "ashton/image_stub"
34
+ require_relative "ashton/particle_emitter"
35
+ require_relative "ashton/pixel_cache"
36
+
37
+ require_relative "ashton/lighting/light_source"
38
+ require_relative "ashton/lighting/manager"
Binary file
@@ -1,12 +1,25 @@
1
- module Gosu
2
- class Color
3
- def self.from_opengl(array)
4
- rgba *array.map {|c| (c * 255).to_i }
5
- end
6
-
7
- # Convert to length 4 array of floats in range 0.0 to 1.0
8
- def to_opengl
9
- [red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0]
10
- end
11
- end
1
+ module Gosu
2
+ class Color
3
+ # @!method self.from_opengl(rgba_array)
4
+ # Convert into an array of floats in range 0.0 to 1.0.
5
+ #
6
+ # @param rgba_array [Array<Float>]
7
+ # @return [Gosu::Color]
8
+
9
+
10
+ # @!method to_opengl
11
+ # Convert into a length 4 array of floats in range 0.0 to 1.0, which
12
+ # can then be passed into OpenGL ruby methods.
13
+ #
14
+ # @example
15
+ # color = Gosu::Color.rgba 128, 0, 0, 255 # => [0.502, 0.0, 0.0, 1.0]
16
+ # glColor4f *color.to_opengl
17
+ #
18
+ # @return [Array<Float>]
19
+
20
+
21
+ # @!method to_i
22
+ # Convert to Gosu-compatible ARGB value (0xAARRGGBB)
23
+ # @return [Integer]
24
+ end
12
25
  end
@@ -0,0 +1,58 @@
1
+ module Gosu
2
+ class Font
3
+ DEFAULT_DRAW_COLOR = Gosu::Color::WHITE
4
+
5
+ alias_method :draw_without_hash, :draw
6
+ protected :draw_without_hash
7
+ def draw(*args)
8
+ args, shader = if args.last.is_a?(Hash)
9
+ [args[0..-2], args.last[:shader]]
10
+ else
11
+ [args, nil]
12
+ end
13
+
14
+ z = args[3]
15
+
16
+ if shader
17
+ shader.enable z
18
+ $window.gl z do
19
+ glActiveTexture GL_TEXTURE0 # Let's make an assumption :)
20
+ shader.color = args[6].is_a?(Color) ? args[6] : DEFAULT_DRAW_COLOR
21
+ end
22
+ end
23
+
24
+ begin
25
+ draw_without_hash *args
26
+ ensure
27
+ shader.disable z if shader
28
+ end
29
+ end
30
+
31
+ alias_method :draw_rel_without_hash, :draw_rel
32
+ protected :draw_rel_without_hash
33
+ def draw_rel(*args)
34
+ args, shader = if args.last.is_a?(Hash)
35
+ [args[0..-2], args.last[:shader]]
36
+ else
37
+ [args, nil]
38
+ end
39
+
40
+ z = args[3]
41
+
42
+ if shader
43
+ shader.enable z
44
+ $window.gl z do
45
+ glActiveTexture GL_TEXTURE0 # Let's make an assumption :)
46
+ shader.color = args[8].is_a?(Color) ? args[8] : DEFAULT_DRAW_COLOR
47
+ end
48
+ end
49
+
50
+ begin
51
+ draw_rel_without_hash *args
52
+ ensure
53
+ shader.disable z if shader
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,16 @@
1
+ require_relative "window"
2
+ require_relative "font"
3
+ require_relative "image"
4
+ require_relative "color"
5
+
6
+ module Gosu
7
+ class << self
8
+ alias_method :original_enable_undocumented_retrofication, :enable_undocumented_retrofication
9
+ protected :original_enable_undocumented_retrofication
10
+
11
+ def enable_undocumented_retrofication
12
+ Ashton::Texture.pixelated = true
13
+ original_enable_undocumented_retrofication
14
+ end
15
+ end
16
+ end
@@ -1,32 +1,96 @@
1
- module Gosu
2
- class Image
3
- alias_method :draw_without_hash, :draw
4
-
5
- def draw(*args)
6
- if args.last.is_a? Hash
7
- shader = args.last[:shader]
8
- shader.use do
9
- shader.image = self
10
- shader.color = args[5].is_a?(Color) ? args[5] : [1, 1, 1, 1]
11
- draw_without_hash *args[0...-1]
12
- end
13
- else
14
- draw_without_hash *args
15
- end
16
- end
17
-
18
- alias_method :draw_rot_without_hash, :draw_rot
19
- def draw_rot(*args)
20
- if args.last.is_a? Hash
21
- shader = args.last[:shader]
22
- shader.use do
23
- shader.image = self
24
- shader.color = args[8].is_a?(Color) ? args[8] : [1, 1, 1, 1]
25
- draw_rot_without_hash *args[0...-1]
26
- end
27
- else
28
- draw_rot_without_hash *args
29
- end
30
- end
31
- end
1
+ module Gosu
2
+ class Image
3
+ DEFAULT_DRAW_COLOR = Gosu::Color::WHITE
4
+
5
+ alias_method :draw_without_hash, :draw
6
+ protected :draw_without_hash
7
+ def draw(*args)
8
+ args, shader = if args.last.is_a?(Hash)
9
+ [args[0..-2], args.last[:shader]]
10
+ else
11
+ [args, nil]
12
+ end
13
+
14
+ z = args[2]
15
+
16
+ if shader
17
+ shader.enable z
18
+ $window.gl z do
19
+ shader.image = self
20
+ shader.color = args[5].is_a?(Color) ? args[5] : DEFAULT_DRAW_COLOR
21
+ end
22
+ end
23
+
24
+ begin
25
+ draw_without_hash *args
26
+ ensure
27
+ shader.disable z if shader
28
+ end
29
+ end
30
+
31
+ alias_method :draw_rot_without_hash, :draw_rot
32
+ protected :draw_rot_without_hash
33
+ def draw_rot(*args)
34
+ args, shader = if args.last.is_a?(Hash)
35
+ [args[0..-2], args.last[:shader]]
36
+ else
37
+ [args, nil]
38
+ end
39
+ z = args[2]
40
+
41
+ if shader
42
+ shader.enable z
43
+ $window.gl z do
44
+ shader.image = self
45
+ shader.color = args[8].is_a?(Color) ? args[8] : DEFAULT_DRAW_COLOR
46
+ end
47
+ end
48
+
49
+ begin
50
+ draw_rot_without_hash *args
51
+ ensure
52
+ shader.disable z if shader
53
+ end
54
+ end
55
+
56
+ # Draw a list of centred sprites by position.
57
+ #
58
+ # @param points [Array<Array>] Array of [x, y] positions
59
+ # @param z [Float] Z-order to draw - Ignored if shader is used.
60
+ # @option options :scale [Float] (1.0) Relative size of the sprites
61
+ # @option options :shader [Ashton::Shader] Shader to apply to all sprites.
62
+ #
63
+ # TODO: Need to use point sprites here, but this is still much faster than individual #draws if using shaders and comparable if not.
64
+ def draw_as_points(points, z, options = {})
65
+ color = options[:color] || DEFAULT_DRAW_COLOR
66
+ scale = options[:scale] || 1.0
67
+ shader = options[:shader]
68
+ mode = options[:mode] || :default
69
+
70
+ if shader
71
+ shader.enable z
72
+ $window.gl z do
73
+ shader.image = self
74
+ shader.color = color
75
+ end
76
+ end
77
+
78
+ begin
79
+ points.each do |x, y|
80
+ draw_rot_without_hash x, y, z, 0, 0.5, 0.5, scale, scale, color, mode
81
+ end
82
+ ensure
83
+ shader.disable z if shader
84
+ end
85
+ end
86
+
87
+ # The cache is a replacement for Texplay's pixel cache system.
88
+ def cache
89
+ @cache ||= Ashton::PixelCache.new self
90
+ end
91
+
92
+ def to_texture
93
+ Ashton::Texture.new self
94
+ end
95
+ end
32
96
  end
@@ -1,36 +1,79 @@
1
- # Set the window global, in case it hasn't been set (e.g. by Chingu)
2
- module Gosu
3
- class Window
4
- class << self
5
- # Used for post-processing effects.
6
- attr_accessor :back_buffer
7
- end
8
-
9
- alias_method :ashton_initialize, :initialize
10
- def initialize(*args, &block)
11
- $window = self
12
- ashton_initialize *args, &block
13
- end
14
-
15
- # TODO: accept multiple shaders.
16
- def post_process(shader)
17
- raise ArgumentError, "Block required" unless block_given?
18
-
19
- Window.back_buffer ||= Ashton::Framebuffer.new width, height
20
-
21
- buffer = Window.back_buffer
22
- buffer.clear
23
-
24
- # allow drawing into the back-buffer.
25
- buffer.use do
26
- yield
27
- end
28
-
29
- # Draw the back-buffer onto the window, utilising the shader.
30
- shader.use do
31
- shader["in_Texture"] = 0
32
- buffer.draw 0, 0
33
- end
34
- end
35
- end
1
+ # Set the window global, in case it hasn't been set (e.g. by Chingu)
2
+ module Gosu
3
+ class Window
4
+ class << self
5
+ WHITE_PIXEL_BLOB = "\xFF" * 4
6
+
7
+ # Used for post-processing effects, but could be used by
8
+ # anyone needing to have a temporary, full-window render buffer.
9
+ def primary_buffer; @primary_buffer ||= Ashton::WindowBuffer.new end
10
+
11
+ # Used for post-processing effects, but could be used by
12
+ # anyone needing to have a temporary, full-window render buffer.
13
+ def secondary_buffer; @secondary_buffer ||= Ashton::WindowBuffer.new end
14
+
15
+ # An image containing a single white pixel. Useful for drawing effects (rectangle, lines, etc).
16
+ def pixel
17
+ @pixel ||= Gosu::Image.new $window, Ashton::ImageStub.new(WHITE_PIXEL_BLOB, 1, 1), true
18
+ end
19
+ end
20
+
21
+ def pixel; Window.pixel end
22
+ def primary_buffer; Window.primary_buffer end
23
+ def secondary_buffer; Window.secondary_buffer end
24
+
25
+ alias_method :ashton_initialize, :initialize
26
+ def initialize(*args, &block)
27
+ $window = self
28
+ ashton_initialize *args, &block
29
+ end
30
+
31
+ alias_method :gl_not_liking_nil, :gl
32
+ protected :gl_not_liking_nil
33
+ def gl(z = nil, &block)
34
+ if z
35
+ gl_not_liking_nil z, &block
36
+ else
37
+ gl_not_liking_nil &block
38
+ end
39
+ end
40
+
41
+ # Full screen post-processing using a fragment shader.
42
+ #
43
+ # Variables set for you in the fragment shader:
44
+ # uniform sampler2D in_Texture; // Texture containing the screen image.
45
+ def post_process(*shaders)
46
+ raise ArgumentError, "Block required" unless block_given?
47
+ raise TypeError, "Can only process with Shaders" unless shaders.all? {|s| s.is_a? Ashton::Shader }
48
+
49
+ # In case no shaders are passed, just run the contents of the block.
50
+ unless shaders.size > 0
51
+ yield
52
+ return
53
+ end
54
+
55
+ buffer1 = primary_buffer
56
+ buffer1.clear
57
+
58
+ # Allow user to draw into a buffer, rather than the window.
59
+ buffer1.render do
60
+ yield
61
+ end
62
+
63
+ if shaders.size > 1
64
+ buffer2 = secondary_buffer # Don't need to clear, since we will :replace.
65
+
66
+ # Draw into alternating buffers, applying each shader in turn.
67
+ shaders[0...-1].each do |shader|
68
+ buffer1, buffer2 = buffer2, buffer1
69
+ buffer1.render do
70
+ buffer2.draw 0, 0, nil, shader: shader, mode: :replace
71
+ end
72
+ end
73
+ end
74
+
75
+ # Draw the buffer directly onto the window, utilising the (last) shader.
76
+ buffer1.draw 0, 0, nil, shader: shaders.last
77
+ end
78
+ end
36
79
  end