ashton 0.0.1alpha → 0.0.2alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -21
- data/README.md +95 -68
- data/Rakefile +41 -23
- data/examples/bloom_example.rb +59 -0
- data/examples/lighting_example.rb +127 -0
- data/examples/media/SmallStar.png +0 -0
- data/examples/media/Starfighter.png +0 -0
- data/examples/media/simple.png +0 -0
- data/examples/noise_example.rb +94 -0
- data/examples/outline_example.rb +86 -0
- data/examples/particle_emitter_example.rb +114 -0
- data/examples/pixelate_example.rb +51 -49
- data/examples/pixelated_texture_example.rb +69 -0
- data/examples/radial_blur_example.rb +60 -62
- data/examples/shader_image_example.rb +74 -41
- data/examples/{shockwave2_example.rb → shockwave_example.rb} +74 -75
- data/examples/stencil_shader_example.rb +104 -0
- data/examples/{framebuffer_example.rb → texture_render_example.rb} +53 -49
- data/examples/{tv_screen_and_noise_example.rb → tv_screen_and_static_example.rb} +59 -59
- data/ext/ashton/GLee.c +18170 -0
- data/ext/ashton/GLee.h +17647 -0
- data/ext/ashton/ashton.c +42 -0
- data/ext/ashton/ashton.h +31 -0
- data/ext/ashton/color.c +45 -0
- data/ext/ashton/color.h +25 -0
- data/ext/ashton/common.h +41 -0
- data/ext/ashton/extconf.rb +42 -0
- data/ext/ashton/fast_math.c +30 -0
- data/ext/ashton/fast_math.h +30 -0
- data/ext/ashton/font.c +8 -0
- data/ext/ashton/font.h +16 -0
- data/ext/ashton/gosu.c +18 -0
- data/ext/ashton/gosu.h +19 -0
- data/ext/ashton/image.c +8 -0
- data/ext/ashton/image.h +16 -0
- data/ext/ashton/particle_emitter.c +788 -0
- data/ext/ashton/particle_emitter.h +171 -0
- data/ext/ashton/pixel_cache.c +237 -0
- data/ext/ashton/pixel_cache.h +58 -0
- data/ext/ashton/shader.c +9 -0
- data/ext/ashton/shader.h +16 -0
- data/ext/ashton/texture.c +442 -0
- data/ext/ashton/texture.h +63 -0
- data/ext/ashton/window.c +8 -0
- data/ext/ashton/window.h +16 -0
- data/lib/ashton.rb +38 -26
- data/lib/ashton/1.9/ashton.so +0 -0
- data/lib/ashton/gosu_ext/color.rb +24 -11
- data/lib/ashton/gosu_ext/font.rb +58 -0
- data/lib/ashton/gosu_ext/gosu_module.rb +16 -0
- data/lib/ashton/gosu_ext/image.rb +95 -31
- data/lib/ashton/gosu_ext/window.rb +78 -35
- data/lib/ashton/image_stub.rb +32 -36
- data/lib/ashton/lighting/light_source.rb +146 -0
- data/lib/ashton/lighting/manager.rb +98 -0
- data/lib/ashton/mixins/version_checking.rb +23 -0
- data/lib/ashton/particle_emitter.rb +87 -0
- data/lib/ashton/pixel_cache.rb +24 -0
- data/lib/ashton/shader.rb +353 -35
- data/lib/ashton/shaders/bloom.frag +41 -0
- data/lib/ashton/shaders/color_inversion.frag +11 -0
- data/lib/ashton/{post_process → shaders}/contrast.frag +16 -16
- data/lib/ashton/{shader → shaders}/default.frag +22 -19
- data/lib/ashton/{shader → shaders}/default.vert +13 -13
- data/lib/ashton/shaders/fade.frag +14 -0
- data/lib/ashton/shaders/grayscale.frag +15 -0
- data/lib/ashton/shaders/include/classicnoise2d.glsl +113 -0
- data/lib/ashton/shaders/include/classicnoise3d.glsl +177 -0
- data/lib/ashton/shaders/include/classicnoise4d.glsl +302 -0
- data/lib/ashton/{include/simplex.glsl → shaders/include/noise2d.glsl} +70 -63
- data/lib/ashton/shaders/include/noise3d.glsl +102 -0
- data/lib/ashton/shaders/include/noise4d.glsl +128 -0
- data/lib/ashton/shaders/include/rand.glsl +5 -0
- data/lib/ashton/shaders/lighting/distort.frag +57 -0
- data/lib/ashton/shaders/lighting/draw_shadows.frag +60 -0
- data/lib/ashton/shaders/lighting/shadow_blur.frag +60 -0
- data/lib/ashton/shaders/mezzotint.frag +22 -0
- data/lib/ashton/shaders/multitexture2.vert +19 -0
- data/lib/ashton/shaders/outline.frag +45 -0
- data/lib/ashton/{post_process → shaders}/pixelate.frag +48 -48
- data/lib/ashton/shaders/radial_blur.frag +63 -0
- data/lib/ashton/shaders/sepia.frag +26 -0
- data/lib/ashton/{post_process/shockwave2.frag → shaders/shockwave.frag} +38 -35
- data/lib/ashton/shaders/signed_distance_field.frag +80 -0
- data/lib/ashton/{post_process/noise.frag → shaders/static.frag} +25 -27
- data/lib/ashton/shaders/stencil.frag +27 -0
- data/lib/ashton/shaders/tv_screen.frag +23 -0
- data/lib/ashton/signed_distance_field.rb +151 -0
- data/lib/ashton/texture.rb +186 -0
- data/lib/ashton/version.rb +2 -2
- data/lib/ashton/window_buffer.rb +16 -0
- data/spec/ashton/ashton_spec.rb +22 -0
- data/spec/ashton/gosu_ext/color_spec.rb +34 -0
- data/spec/ashton/gosu_ext/font_spec.rb +57 -0
- data/spec/ashton/gosu_ext/gosu_spec.rb +11 -0
- data/spec/ashton/gosu_ext/image_spec.rb +66 -0
- data/spec/ashton/gosu_ext/window_spec.rb +71 -0
- data/spec/ashton/image_stub_spec.rb +46 -0
- data/spec/ashton/particle_emitter_spec.rb +123 -0
- data/spec/ashton/pixel_cache_spec.rb +153 -0
- data/spec/ashton/shader_spec.rb +152 -0
- data/spec/ashton/signed_distance_field_spec.rb +163 -0
- data/spec/ashton/texture_spec.rb +347 -0
- data/spec/helper.rb +12 -0
- metadata +159 -28
- data/examples/output/README.txt +0 -1
- data/lib/ashton/base_shader.rb +0 -172
- data/lib/ashton/framebuffer.rb +0 -183
- data/lib/ashton/post_process.rb +0 -83
- data/lib/ashton/post_process/default.vert +0 -9
- data/lib/ashton/post_process/fade.frag +0 -11
- data/lib/ashton/post_process/mezzotint.frag +0 -24
- data/lib/ashton/post_process/radial_blur.frag +0 -31
- data/lib/ashton/post_process/sepia.frag +0 -19
- data/lib/ashton/post_process/shockwave.frag +0 -40
- 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
|
+
|
data/ext/ashton/window.c
ADDED
data/ext/ashton/window.h
ADDED
data/lib/ashton.rb
CHANGED
@@ -1,26 +1,38 @@
|
|
1
|
-
require 'opengl'
|
2
|
-
require 'gosu'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
class
|
13
|
-
|
14
|
-
class
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|