mittsu 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14853ca4b6cc897edcdba73d196cc99ad2d80c9d
4
- data.tar.gz: 857d141324a406aa0e420bbc0a0685348b373c5f
3
+ metadata.gz: 888b8fed281195b187add2cce25a4ef54f737a11
4
+ data.tar.gz: 5416e8ec76e74ab04725f9e79d5b1b2a0f744b28
5
5
  SHA512:
6
- metadata.gz: 4a85835765393ad611593a0cfb1980518edf6a1bb4e38d331fe5d6033323d6b4fada55f1daefab7f39badad07150446f51db732b4f12beff8acca56e53fbc59d
7
- data.tar.gz: 45463c3e8276ca92a07965d117d3749a53202c16d99e8d810c13441d53e509325d08147ada69fe93904a7cde5b6d2f3b326e58be5f7d342f2766adfc40e2a4b7
6
+ metadata.gz: 6bda9102f024f4c5f611ae1e46c603bc16fa0d7d73e7c5665d57c9711bc29767d9de6a6c79928cebe8362eeb5bbb2125b17b54cc39c28b3804a431e5393cc472
7
+ data.tar.gz: dab44a21708d30c12eac2ba653e59114f5a3c61b68624ba98b3bc6b11277c435a03fcda783acf67cfe33dfd71dfdfd81dc44673be7bd2621363a90e83dd66aee
data/README.md CHANGED
@@ -23,7 +23,7 @@ Mittsu depends on Ruby 2.x, OpenGL 3.3+, and GLFW 3.1.x
23
23
  $ brew install glfw3
24
24
 
25
25
  # Ubuntu
26
- $ sudo apt-get install libglfw3-dev
26
+ $ sudo apt-get install libglfw3
27
27
  ```
28
28
 
29
29
  **NOTE:** On Windows, you will have to manually specify the glfw3.dll path in an environment variable
@@ -1,11 +1,11 @@
1
1
  module Mittsu
2
2
  module ImageUtils
3
3
  class << self
4
- def load_texture(url, mapping = Texture::DEFAULT_MAPPING)
4
+ def load_texture(url, mapping = Texture::DEFAULT_MAPPING, flip: true, flop: false)
5
5
  loader = ImageLoader.new
6
6
 
7
7
  Texture.new(nil, mapping).tap do |texture|
8
- image = loader.load(url, flip: true)
8
+ image = loader.load(url, flip: flip, flop: flop)
9
9
  texture.image = image
10
10
  texture.needs_update = true
11
11
 
@@ -11,12 +11,12 @@ module Mittsu
11
11
 
12
12
  def load(url, flip: false, flop: false)
13
13
  chache_url = "#{url}?flip=#{flip}&flop=#{flop}"
14
- cached = Cache.get(chache_url )
14
+ cached = Cache.get(chache_url)
15
15
  return cached unless cached.nil?
16
16
 
17
17
  png_image = ChunkyPNG::Image.from_file(url)
18
- png_image = png_image.flip_vertically if flip
19
- png_image = png_image.flip_horizontally if flop
18
+ png_image.flip_horizontally! if flip
19
+ png_image.flip_vertically! if flop
20
20
  rgba_data = png_image.to_rgba_stream
21
21
 
22
22
  image = Image.new(png_image.width, png_image.height, rgba_data)
@@ -0,0 +1,116 @@
1
+ module Mittsu
2
+ module GenericLib
3
+ def discover
4
+ case OpenGL.get_platform
5
+ when :OPENGL_PLATFORM_WINDOWS
6
+ self::Windows.new
7
+ when :OPENGL_PLATFORM_MACOSX
8
+ self::MacOS.new
9
+ when :OPENGL_PLATFORM_LINUX
10
+ self::Linux.new
11
+ else
12
+ fail "Unsupported platform."
13
+ end
14
+ end
15
+
16
+ class Linux
17
+ def path
18
+ return nil if file_path.nil?
19
+ File.dirname file_path
20
+ end
21
+
22
+ def file
23
+ return nil if file_path.nil?
24
+ File.basename file_path
25
+ end
26
+
27
+ class << self
28
+ def kernel_module_in_use
29
+ lspci_line = `lspci -nnk | grep -i vga -A3 | grep 'in use'`
30
+ /in use:\s*(\S+)/ =~ lspci_line && $1
31
+ rescue
32
+ ''
33
+ end
34
+
35
+ def libgl_paths
36
+ Dir.glob('/usr/lib*/**/libGL.so*')
37
+ rescue
38
+ []
39
+ end
40
+
41
+ def sixtyfour_bits?
42
+ 1.size == 8
43
+ end
44
+
45
+ def ldconfig
46
+ `ldconfig -p | grep 'libGL\\.so'`.lines
47
+ rescue
48
+ []
49
+ end
50
+ end
51
+
52
+ private
53
+ def file_path
54
+ @_file_path ||= begin
55
+ ldconfig_lib || driver_specific_lib || sixtyfour_bit_lib || fallback_lib || give_up
56
+ end.tap do |result|
57
+ print_debug_info(result) if DEBUG
58
+ end
59
+ end
60
+
61
+ def ldconfig_lib
62
+ return nil if ldconfig.empty?
63
+ @_debug = { source: 'ldconfig', info: ldconfig.inspect } if DEBUG
64
+ ldconfig_for_arch = ldconfig.reject { |lib| @loader.sixtyfour_bits? ^ ldconfig_64?(lib) }
65
+ ldconfig_for_arch.first.match(/=> (\/.*)$/)[1]
66
+ end
67
+
68
+ def ldconfig_64?(lib)
69
+ lib =~ /\([^\)]*64[^\)]*\) =>/
70
+ end
71
+
72
+ def driver_specific_lib
73
+ return nil if libs.empty?
74
+ @_debug = { source: 'driver', info: kernel_module } if DEBUG
75
+ libs.select { |lib| lib =~ /nvidia/ }.first if kernel_module =~ /nvidia/
76
+ end
77
+
78
+ def sixtyfour_bit_lib
79
+ return nil if libs.empty?
80
+ sixtyfour_bit_libs = libs.select { |lib| lib =~ /64/ }
81
+ @_debug = { source: '64', info: sixtyfour_bit_libs.inspect } if DEBUG
82
+ sixtyfour_bit_libs.first if @loader.sixtyfour_bits?
83
+ end
84
+
85
+ def fallback_lib
86
+ return nil if libs.empty?
87
+ @_debug = { source: 'fallback', info: libs.inspect } if DEBUG
88
+ libs.first
89
+ end
90
+
91
+ def give_up
92
+ @_debug = { source: 'none', info: nil } if DEBUG
93
+ nil
94
+ end
95
+
96
+ def kernel_module
97
+ @_kernel_module ||= @loader.kernel_module_in_use
98
+ end
99
+
100
+ def libs
101
+ @_libs ||= @loader.libgl_paths.sort_by(&:length)
102
+ end
103
+
104
+ def ldconfig
105
+ @_ldconfig ||= @loader.ldconfig
106
+ end
107
+
108
+ def print_debug_info(result)
109
+ puts "Loading lib path: #{result.inspect}"
110
+ puts "Source: #{@_debug[:source]}"
111
+ puts "Info: #{@_debug[:info]}"
112
+ puts "64-bit? #{@loader.sixtyfour_bits?}"
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,42 @@
1
+ require 'mittsu/renderers/generic_lib'
2
+
3
+ module Mittsu
4
+ module GLFWLib
5
+ extend GenericLib
6
+
7
+ class Linux < GenericLib::Linux
8
+ def initialize(loader = Linux)
9
+ @loader = loader
10
+ end
11
+
12
+ class << self
13
+ def libgl_paths
14
+ Dir.glob('/usr/lib*/**/libglfw*.so*')
15
+ rescue
16
+ []
17
+ end
18
+
19
+ def ldconfig
20
+ `ldconfig -p | grep 'libglfw3\\?\\.so'`.lines
21
+ rescue
22
+ []
23
+ end
24
+ end
25
+ end
26
+
27
+ class Windows
28
+ def path; nil; end
29
+ def file; nil; end
30
+ end
31
+
32
+ class MacOS
33
+ def path
34
+ '/usr/local/lib'
35
+ end
36
+
37
+ def file
38
+ 'libglfw3.dylib'
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,24 +1,12 @@
1
1
  require 'opengl'
2
2
  require 'glfw'
3
3
 
4
- GLFW_LIB_EXT = OpenGL.get_platform == :OPENGL_PLATFORM_MACOSX ? 'dylib' : 'so'
5
- if OpenGL.get_platform != :OPENGL_PLATFORM_TEST
6
- GLFW_LIB = ENV["MITTSU_LIBGLFW_FILE"] || begin
7
- "lib#{`pkg-config --libs-only-l glfw3`.gsub(/^-l/, '').chomp.strip}.#{GLFW_LIB_EXT}"
8
- rescue
9
- "libglfw.#{GLFW_LIB_EXT}"
10
- end
11
- GLFW_LIB_PATH = ENV["MITTSU_LIBGLFW_PATH"] || begin
12
- s = `pkg-config glfw3 --libs-only-L`.gsub(/^-L/, '').chomp.strip
13
- s.empty? ? nil : s
14
- rescue
15
- nil
16
- end
4
+ require 'mittsu'
5
+ require 'mittsu/renderers/glfw_lib'
6
+ glfw_lib = Mittsu::GLFWLib.discover
7
+ GLFW.load_lib(ENV["MITTSU_LIBGLFW_FILE"] || glfw_lib.file, ENV["MITTSU_LIBGLFW_PATH"] || glfw_lib.path)
17
8
 
18
- GLFW.load_lib GLFW_LIB, GLFW_LIB_PATH
19
-
20
- include GLFW
21
- end
9
+ include GLFW
22
10
 
23
11
  module Mittsu
24
12
  module GLFW
@@ -1,130 +1,23 @@
1
- module OpenGLLib
2
- def self.discover
3
- case OpenGL.get_platform
4
- when :OPENGL_PLATFORM_WINDOWS
5
- Windows.new
6
- when :OPENGL_PLATFORM_MACOSX
7
- MacOS.new
8
- when :OPENGL_PLATFORM_LINUX
9
- Linux.new
10
- else
11
- fail "Unsupported platform."
12
- end
13
- end
1
+ require 'mittsu/renderers/generic_lib'
14
2
 
15
- class Linux
16
- def initialize(loader = Linux)
17
- @loader = loader
18
- end
3
+ module Mittsu
4
+ module OpenGLLib
5
+ extend GenericLib
19
6
 
20
- def path
21
- return nil if file_path.nil?
22
- File.dirname file_path
7
+ class Linux < GenericLib::Linux
8
+ def initialize(loader = Linux)
9
+ @loader = loader
10
+ end
23
11
  end
24
12
 
25
- def file
26
- return nil if file_path.nil?
27
- File.basename file_path
13
+ class Windows
14
+ def path; nil; end
15
+ def file; nil; end
28
16
  end
29
17
 
30
- class << self
31
- def kernel_module_in_use
32
- lspci_line = `lspci -nnk | grep -i vga -A3 | grep 'in use'`
33
- /in use:\s*(\S+)/ =~ lspci_line && $1
34
- rescue
35
- ''
36
- end
37
-
38
- def libgl_paths
39
- Dir.glob('/usr/lib*/**/libGL.so*')
40
- rescue
41
- []
42
- end
43
-
44
- def sixtyfour_bits?
45
- 1.size == 8
46
- end
47
-
48
- def ldconfig
49
- `ldconfig -p | grep 'libGL\\.so'`.lines
50
- rescue
51
- []
52
- end
18
+ class MacOS
19
+ def path; nil; end
20
+ def file; nil; end
53
21
  end
54
-
55
- private
56
- def file_path
57
- @_file_path ||= begin
58
- ldconfig_lib || driver_specific_lib || sixtyfour_bit_lib || fallback_lib || give_up
59
- end.tap do |result|
60
- print_debug_info(result) if Mittsu::DEBUG
61
- end
62
- end
63
-
64
- def ldconfig_lib
65
- return nil if ldconfig.empty?
66
- @_debug = { source: 'ldconfig', info: ldconfig.inspect } if Mittsu::DEBUG
67
- ldconfig_for_arch = ldconfig.reject { |lib| @loader.sixtyfour_bits? ^ ldconfig_64?(lib) }
68
- ldconfig_for_arch.first.match(/=> (\/.*)$/)[1]
69
- end
70
-
71
- def ldconfig_64?(lib)
72
- lib =~ /\([^\)]*64[^\)]*\) =>/
73
- end
74
-
75
- def driver_specific_lib
76
- return nil if libs.empty?
77
- @_debug = { source: 'driver', info: kernel_module } if Mittsu::DEBUG
78
- libs.select { |lib| lib =~ /nvidia/ }.first if kernel_module =~ /nvidia/
79
- end
80
-
81
- def sixtyfour_bit_lib
82
- return nil if libs.empty?
83
- sixtyfour_bit_libs = libs.select { |lib| lib =~ /64/ }
84
- @_debug = { source: '64', info: sixtyfour_bit_libs.inspect } if Mittsu::DEBUG
85
- sixtyfour_bit_libs.first if @loader.sixtyfour_bits?
86
- end
87
-
88
- def fallback_lib
89
- return nil if libs.empty?
90
- @_debug = { source: 'fallback', info: libs.inspect } if Mittsu::DEBUG
91
- libs.first
92
- end
93
-
94
- def give_up
95
- @_debug = { source: 'none', info: nil } if Mittsu::DEBUG
96
- nil
97
- end
98
-
99
- def kernel_module
100
- @_kernel_module ||= @loader.kernel_module_in_use
101
- end
102
-
103
- def libs
104
- @_libs ||= @loader.libgl_paths.sort_by(&:length)
105
- end
106
-
107
- def ldconfig
108
- @_ldconfig ||= @loader.ldconfig
109
- end
110
-
111
- def print_debug_info(result)
112
- puts "Loading lib path: #{result.inspect}"
113
- puts "Source: #{@_debug[:source]}"
114
- puts "Info: #{@_debug[:info]}"
115
- puts "64-bit? #{@loader.sixtyfour_bits?}"
116
- end
117
- end
118
-
119
- # TODO
120
- class Windows
121
- def path; nil; end
122
- def file; nil; end
123
- end
124
-
125
- # TODO
126
- class MacOS
127
- def path; nil; end
128
- def file; nil; end
129
22
  end
130
23
  end
@@ -4,7 +4,7 @@ require 'fiddle'
4
4
 
5
5
 
6
6
  require 'mittsu/renderers/opengl/opengl_lib'
7
- opengl_lib = OpenGLLib.discover
7
+ opengl_lib = Mittsu::OpenGLLib.discover
8
8
  OpenGL.load_lib(ENV["MITTSU_LIBGL_FILE"] || opengl_lib.file, ENV["MITTSU_LIBGL_PATH"] || opengl_lib.path)
9
9
 
10
10
  require 'mittsu'
@@ -1,4 +1,4 @@
1
1
  module Mittsu
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  REVISION = "71"
4
4
  end
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.required_ruby_version = '>= 2.0.0'
24
- spec.requirements << 'ImageMagick 6.4.9 or later'
25
24
  spec.requirements << 'OpenGL 3.3+ capable hardware and drivers'
26
25
 
27
26
  spec.add_runtime_dependency 'opengl-bindings', "~> 1.5"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mittsu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-05 00:00:00.000000000 Z
11
+ date: 2017-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opengl-bindings
@@ -235,6 +235,8 @@ files:
235
235
  - lib/mittsu/objects/line.rb
236
236
  - lib/mittsu/objects/mesh.rb
237
237
  - lib/mittsu/renderers.rb
238
+ - lib/mittsu/renderers/generic_lib.rb
239
+ - lib/mittsu/renderers/glfw_lib.rb
238
240
  - lib/mittsu/renderers/glfw_window.rb
239
241
  - lib/mittsu/renderers/opengl/core/geometry.rb
240
242
  - lib/mittsu/renderers/opengl/core/object_3d.rb
@@ -380,10 +382,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
380
382
  - !ruby/object:Gem::Version
381
383
  version: '0'
382
384
  requirements:
383
- - ImageMagick 6.4.9 or later
384
385
  - OpenGL 3.3+ capable hardware and drivers
385
386
  rubyforge_project:
386
- rubygems_version: 2.5.2
387
+ rubygems_version: 2.5.1
387
388
  signing_key:
388
389
  specification_version: 4
389
390
  summary: 3D Graphics Library for Ruby