pixo 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8aa1f77b18b26d4780cb42129a19d2d287001a9a
4
- data.tar.gz: 7029163344d64ce5696b5f6aca011662c2f1b665
3
+ metadata.gz: f0682c352898cecd4796798bf2ab28253d1f5d05
4
+ data.tar.gz: 31f453e1d0410a72cc41223469c946144b1af45c
5
5
  SHA512:
6
- metadata.gz: '0925db69c959cf66caac3972316390f9539f54d81db691dd3079d27a354cfc79223726be2715c0e90f4b737cd2284581c2530a5aa5e7912511cd021977eb4360'
7
- data.tar.gz: 5e109416c55cf554aa8c9125402a6bef21fd86f51d8ca22e679b3620bd892e0aaf2f385ab3cab2528ba8431a2a1495941b5146fe4d53c4c72654eebddd2cf57c
6
+ metadata.gz: c5d8c6b7e35a86d771ce5d035b924d7cf2f243115d0ab5aa1a5d88f3b61b5c2b314aff770d1b0cc0c8b33e3b405cc315269e93e103496e10e1fb5ae7368cc5b1
7
+ data.tar.gz: e889dcd34ecbc87ffdc6b26546338b7a84f73d32d248ae693ce745c7a94caa20d7fee2bfeb110db55f2b1498b4fa53675508e467c4b48e555c9da02344a44479
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pixo (0.2.1)
4
+ pixo (0.2.2)
5
5
  concurrent-ruby
6
6
 
7
7
  GEM
@@ -104,7 +104,7 @@ VALUE application_initialize(VALUE self)
104
104
  return self;
105
105
  }
106
106
 
107
- VALUE application_tick(VALUE self, VALUE r_pattern)
107
+ VALUE application_tick(VALUE self, VALUE r_pattern, VALUE r_brightness)
108
108
  {
109
109
  GLenum glErr;
110
110
  ApplicationHolder * app_holder;
@@ -113,6 +113,8 @@ VALUE application_tick(VALUE self, VALUE r_pattern)
113
113
  PatternHolder * pattern_holder;
114
114
  Data_Get_Struct(r_pattern, PatternHolder, pattern_holder);
115
115
 
116
+ float brightness = (float)NUM2DBL(r_brightness);
117
+
116
118
  if (app_holder->window) {
117
119
  glfwMakeContextCurrent(app_holder->window);
118
120
 
@@ -132,7 +134,7 @@ VALUE application_tick(VALUE self, VALUE r_pattern)
132
134
  int width, height;
133
135
  glfwGetFramebufferSize(app_holder->window, &width, &height);
134
136
 
135
- app_holder->app->tick(pattern_holder->pattern, width, height);
137
+ app_holder->app->tick(pattern_holder->pattern, brightness, width, height);
136
138
 
137
139
  app_holder->app->move_perspective_to_camera();
138
140
 
@@ -27,4 +27,4 @@ VALUE application_initialize(VALUE self);
27
27
 
28
28
  VALUE application_add_fadecandy(VALUE self, VALUE fc);
29
29
 
30
- VALUE application_tick(VALUE self, VALUE r_pattern);
30
+ VALUE application_tick(VALUE self, VALUE r_pattern, VALUE r_brightness);
@@ -45,7 +45,7 @@ extern "C" void Init_libpixgem() {
45
45
  rb_define_alloc_func(ApplicationClass, application_allocate);
46
46
  rb_define_method(ApplicationClass, "initialize", (VALUE(*)(ANYARGS))application_initialize, 0);
47
47
  rb_define_method(ApplicationClass, "close", (VALUE(*)(ANYARGS))application_close, 0);
48
- rb_define_method(ApplicationClass, "tick", (VALUE(*)(ANYARGS))application_tick, 1);
48
+ rb_define_method(ApplicationClass, "tick", (VALUE(*)(ANYARGS))application_tick, 2);
49
49
  rb_define_method(ApplicationClass, "add_fadecandy", (VALUE(*)(ANYARGS))application_add_fadecandy, 1);
50
50
 
51
51
  VALUE FadeCandyClass = rb_define_class_under(Native, "FadeCandy", rb_cObject);
@@ -28,7 +28,7 @@ namespace Pixlib {
28
28
 
29
29
  void move_perspective_to_camera();
30
30
 
31
- void tick(Pattern* pattern, int width, int height);
31
+ void tick(Pattern* pattern, float brightness, int width, int height);
32
32
  private:
33
33
  Scene scene;
34
34
  std::vector<LedCluster*> led_clusters;
@@ -31,7 +31,7 @@ namespace Pixlib {
31
31
  // Render the mesh
32
32
  virtual void Draw(const Shader& shader);
33
33
 
34
- void render(const IsoCamera& viewed_from, const Pattern& pattern);
34
+ void render(const IsoCamera& viewed_from, const Pattern& pattern, float brightness);
35
35
 
36
36
  const Texture& getPatternTexture();
37
37
 
@@ -14,12 +14,13 @@ namespace Pixlib {
14
14
  public:
15
15
  LedRender(const Texture& renderTo);
16
16
 
17
- void render(const IsoCamera& perspective, uint8_t* data, size_t size);
17
+ void render(const IsoCamera& perspective, float brightness, uint8_t* data, size_t size);
18
18
 
19
19
  Texture getTexture();
20
20
 
21
21
  LedMesh* leds;
22
22
 
23
+
23
24
  private:
24
25
  GLuint FramebufferName;
25
26
  Texture renderedTexture;
@@ -29,7 +30,6 @@ namespace Pixlib {
29
30
  GLuint active_pbo;
30
31
  OrthoCamera camera;
31
32
 
32
-
33
33
  Shader shader;
34
34
  void setupLights(const IsoCamera& perspective);
35
35
  };
@@ -48,11 +48,11 @@ namespace Pixlib {
48
48
  viewed_from.moveTowards(camera, scene.getTimeDelta()*0.8);
49
49
  }
50
50
 
51
- void App::tick(Pattern* pattern, int width, int height) {
51
+ void App::tick(Pattern* pattern, float brightness, int width, int height) {
52
52
  camera.rotate(scene_render_time() * 5);
53
53
 
54
54
  for (LedCluster* led_cluster : led_clusters) {
55
- led_cluster->render(viewed_from, *pattern);
55
+ led_cluster->render(viewed_from, *pattern, brightness);
56
56
  }
57
57
  scene.render(camera, width, height);
58
58
  }
@@ -56,11 +56,11 @@ namespace Pixlib {
56
56
  leds_for_display.Draw(shader);
57
57
  }
58
58
 
59
- void LedCluster::render(const IsoCamera& viewed_from, const Pattern& pattern)
59
+ void LedCluster::render(const IsoCamera& viewed_from, const Pattern& pattern, float brightness)
60
60
  {
61
61
  render_timer.start();
62
62
  pattern_render.render(pattern);
63
- fb_render.render(viewed_from, fadecandy->getData(), numLeds()*3);
63
+ fb_render.render(viewed_from, brightness, fadecandy->getData(), numLeds()*3);
64
64
  render_timer.end();
65
65
 
66
66
  fadecandy->update();
@@ -50,9 +50,11 @@ namespace Pixlib {
50
50
  uniform sampler2D texture0;
51
51
  uniform sampler2D texture1;
52
52
 
53
+ uniform float brightness;
54
+
53
55
  void main()
54
56
  {
55
- color = texture(texture1, TexCoords);
57
+ color = texture(texture1, TexCoords) * brightness;
56
58
  })")
57
59
  {
58
60
  // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer.
@@ -89,7 +91,7 @@ namespace Pixlib {
89
91
  active_pbo = 0;
90
92
  }
91
93
 
92
- void LedRender::render(const IsoCamera& perspective, uint8_t* buffer, size_t size) {
94
+ void LedRender::render(const IsoCamera& perspective, float brightness, uint8_t* buffer, size_t size) {
93
95
  glEnable(GL_DEPTH_TEST);
94
96
  glDepthFunc(GL_LESS);
95
97
 
@@ -111,6 +113,8 @@ namespace Pixlib {
111
113
  glUniformMatrix4fv(glGetUniformLocation(shader.Program, "proj_from"), 1, GL_FALSE, glm::value_ptr(led_projection));
112
114
  glUniformMatrix4fv(glGetUniformLocation(shader.Program, "view_from"), 1, GL_FALSE, glm::value_ptr(led_view));
113
115
 
116
+ glUniform1f(glGetUniformLocation(shader.Program, "brightness"), brightness);
117
+
114
118
  leds->Draw(shader);
115
119
 
116
120
  glBindBuffer(GL_PIXEL_PACK_BUFFER, pbos[active_pbo]);
@@ -5,7 +5,7 @@ require File.expand_path('../../libpixgem', __FILE__)
5
5
 
6
6
  module Pixo
7
7
  class Application < Pixo::Native::Application
8
- attr_accessor :running
8
+ attr_accessor :running, :leds_on
9
9
 
10
10
  def self.instance
11
11
  @instance ||= Pixo::Application.new
@@ -13,7 +13,7 @@ module Pixo
13
13
 
14
14
  def run
15
15
  while(running)
16
- self.running = tick(active_pattern) && running
16
+ self.running = tick(active_pattern, brightness) && running
17
17
  end
18
18
  close
19
19
  end
@@ -47,12 +47,27 @@ module Pixo
47
47
  pattern.reset_start
48
48
  @active_pattern = pattern
49
49
  end
50
-
50
+
51
+ def brightness=(val)
52
+ if val > 1.0
53
+ val = 1.0
54
+ elsif val < 0.0
55
+ val = 0.0
56
+ end
57
+ @brightness = val
58
+ end
59
+
60
+ def brightness
61
+ leds_on ? @brightness : 0.0
62
+ end
63
+
51
64
  private
52
65
 
53
66
  def initialize()
54
67
  super
55
68
  self.running = true
69
+ self.brightness = 1.0
70
+ self.leds_on = true
56
71
 
57
72
  add_fadecandy(Pixo::Native::FadeCandy.new('localhost', 8))
58
73
  end
@@ -0,0 +1,98 @@
1
+ module Pixo
2
+ class Renderer
3
+ attr_reader :service, :service_thread
4
+
5
+ def initialize()
6
+ i, o, t = Open3.popen2('bundle exec pixo')
7
+ @service = Pixo::Ipc::Service.new(o, i)
8
+ @service_thread = Thread.new { self.service.run }
9
+ end
10
+
11
+ def pattern_names
12
+ service.request(Pixo::Renderer::GetPatternNames.new)
13
+ end
14
+
15
+ def active_pattern
16
+ service.request(Pixo::Renderer::GetPatternName.new)
17
+ end
18
+
19
+ def set_pattern(name)
20
+ service.request(Pixo::Renderer::SetPattern.new(name))
21
+ end
22
+
23
+ def brightness=(brightness)
24
+ service.request(Pixo::Renderer::SetBrightness.new(brightness))
25
+ end
26
+
27
+ def brightness
28
+ service.request(Pixo::Renderer::GetBrightness.new())
29
+ end
30
+
31
+ def leds_on=(leds_on)
32
+ service.request(Pixo::Renderer::SetLedsOn.new(leds_on))
33
+ end
34
+
35
+ def leds_on
36
+ service.request(Pixo::Renderer::GetLedsOn.new())
37
+ end
38
+
39
+ private
40
+ class GetPatternName
41
+ def call
42
+ Pixo::Application.instance.patterns.key(Pixo::Application.instance.active_pattern)
43
+ end
44
+ end
45
+
46
+ class GetPatternNames
47
+ def call
48
+ Pixo::Application.instance.patterns.keys
49
+ end
50
+ end
51
+
52
+ class SetPattern
53
+ def initialize(pattern_name)
54
+ @pattern_name = pattern_name
55
+ end
56
+
57
+ def call
58
+ pattern = Pixo::Application.instance.patterns[@pattern_name]
59
+ Pixo::Application.instance.active_pattern = pattern if pattern
60
+ @pattern_name
61
+ end
62
+ end
63
+
64
+ class GetBrightness
65
+ def call
66
+ Pixo::Application.instance.brightness
67
+ end
68
+ end
69
+
70
+ class SetBrightness
71
+ def initialize(brightness)
72
+ @brightness = brightness
73
+ end
74
+
75
+ def call
76
+ Pixo::Application.instance.brightness = @brightness
77
+ end
78
+ end
79
+
80
+
81
+ class GetLedsOn
82
+ def call
83
+ Pixo::Application.instance.leds_on
84
+ end
85
+ end
86
+
87
+ class SetLedsOn
88
+ def initialize(leds_on)
89
+ @leds_on = leds_on
90
+ end
91
+
92
+ def call
93
+ Pixo::Application.instance.leds_on = @leds_on
94
+ end
95
+ end
96
+
97
+ end
98
+ end
data/lib/pixo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pixo
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/pixo.rb CHANGED
@@ -1,51 +1,8 @@
1
1
  require "pixo/version"
2
2
  require "pixo/ipc/service"
3
+ require "pixo/renderer"
3
4
  require "open3"
4
5
 
5
6
  module Pixo
6
- class GetPatternName
7
- def call
8
- Pixo::Application.instance.patterns.key(Pixo::Application.instance.active_pattern)
9
- end
10
- end
11
-
12
- class GetPatternNames
13
- def call
14
- Pixo::Application.instance.patterns.keys
15
- end
16
- end
17
7
 
18
- class SetPattern
19
- def initialize(pattern_name)
20
- @pattern_name = pattern_name
21
- end
22
-
23
- def call
24
- pattern = Pixo::Application.instance.patterns[@pattern_name]
25
- Pixo::Application.instance.active_pattern = pattern if pattern
26
- @pattern_name
27
- end
28
- end
29
-
30
- class Renderer
31
- attr_reader :service, :service_thread
32
-
33
- def initialize()
34
- i, o, t = Open3.popen2('bundle exec pixo')
35
- @service = Pixo::Ipc::Service.new(o, i)
36
- @service_thread = Thread.new { self.service.run }
37
- end
38
-
39
- def pattern_names
40
- service.request(Pixo::GetPatternNames.new)
41
- end
42
-
43
- def active_pattern
44
- service.request(Pixo::GetPatternName.new)
45
- end
46
-
47
- def set_pattern(name)
48
- service.request(Pixo::SetPattern.new(name))
49
- end
50
- end
51
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Constantine
@@ -1541,6 +1541,7 @@ files:
1541
1541
  - lib/pixo.rb
1542
1542
  - lib/pixo/application.rb
1543
1543
  - lib/pixo/ipc/service.rb
1544
+ - lib/pixo/renderer.rb
1544
1545
  - lib/pixo/version.rb
1545
1546
  - pixo.gemspec
1546
1547
  homepage: https://github.com/cconstantine