diff --git a/README.md b/README.md index dfe775d2..99ae5129 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,10 @@ Mittsu depends on Ruby 2.x, OpenGL 3.3+, and GLFW 3.1.x $ brew install glfw3 # Ubuntu -$ sudo apt-get install libglfw3 +$ sudo apt install libglfw3 + +# Fedora +$ sudo dnf install glfw ``` **NOTE:** On Windows, you will have to manually specify the glfw3.dll path in an environment variable diff --git a/lib/mittsu/renderers/generic_lib.rb b/lib/mittsu/renderers/generic_lib.rb index 28bfa9f8..2b71a2a0 100644 --- a/lib/mittsu/renderers/generic_lib.rb +++ b/lib/mittsu/renderers/generic_lib.rb @@ -18,18 +18,15 @@ def discover class Base def path; nil; end - def file; nil; end end class Linux < Base def path - return nil if file_path.nil? - File.dirname file_path - end - - def file - return nil if file_path.nil? - File.basename file_path + @_path ||= begin + ldconfig_lib || driver_specific_lib || sixtyfour_bit_lib || fallback_lib || give_up + end.tap do |result| + print_debug_info(result) if DEBUG + end end class << self @@ -41,7 +38,7 @@ def kernel_module_in_use '' end - def libgl_paths + def lib_paths Dir.glob('/usr/lib*/**/libGL.so*') rescue [] @@ -59,13 +56,6 @@ def ldconfig end private - def file_path - @_file_path ||= begin - ldconfig_lib || driver_specific_lib || sixtyfour_bit_lib || fallback_lib || give_up - end.tap do |result| - print_debug_info(result) if DEBUG - end - end def ldconfig_lib return nil if ldconfig.empty? @@ -107,7 +97,7 @@ def kernel_module end def libs - @_libs ||= @loader.libgl_paths.sort_by(&:length) + @_libs ||= @loader.lib_paths.sort_by(&:length) end def ldconfig diff --git a/lib/mittsu/renderers/glfw_lib.rb b/lib/mittsu/renderers/glfw_lib.rb index 0f6a5f32..2c19d716 100644 --- a/lib/mittsu/renderers/glfw_lib.rb +++ b/lib/mittsu/renderers/glfw_lib.rb @@ -10,7 +10,7 @@ def initialize(loader = Linux) end class << self - def libgl_paths + def lib_paths Dir.glob('/usr/lib*/**/libglfw*.so*') rescue [] @@ -27,7 +27,7 @@ def ldconfig end class Windows < GenericLib::Base - def file + def path 'glfw3.dll' end end @@ -38,19 +38,11 @@ class MacOS < GenericLib::Base '/opt/homebrew/**'] def path - File.dirname(match.to_s) - end - - def file - File.basename(match.to_s) + @_path ||= find_match&.to_s end private - def match - @match ||= find_match - end - def find_match SEARCH_GLOBS.each do |glob| matches = Dir.glob("#{glob}/libglfw*.dylib") diff --git a/lib/mittsu/renderers/glfw_window.rb b/lib/mittsu/renderers/glfw_window.rb index 2658f8fe..a3529bdd 100644 --- a/lib/mittsu/renderers/glfw_window.rb +++ b/lib/mittsu/renderers/glfw_window.rb @@ -4,7 +4,7 @@ require 'mittsu/utils' require 'mittsu/renderers/glfw_lib' glfw_lib = Mittsu::GLFWLib.discover -::GLFW.load_lib(ENV["MITTSU_LIBGLFW_FILE"] || glfw_lib.file, ENV["MITTSU_LIBGLFW_PATH"] || glfw_lib.path) unless Mittsu.test? +::GLFW.load_lib(ENV["MITTSU_LIBGLFW_PATH"] || glfw_lib.path, Mittsu.debug?) unless Mittsu.test? module Mittsu module GLFW diff --git a/lib/mittsu/renderers/opengl_renderer.rb b/lib/mittsu/renderers/opengl_renderer.rb index fd96ecd8..130d0fc9 100644 --- a/lib/mittsu/renderers/opengl_renderer.rb +++ b/lib/mittsu/renderers/opengl_renderer.rb @@ -4,7 +4,7 @@ require 'mittsu/renderers/opengl/opengl_lib' opengl_lib = Mittsu::OpenGLLib.discover -GL.load_lib(ENV["MITTSU_LIBGL_FILE"] || opengl_lib.file, ENV["MITTSU_LIBGL_PATH"] || opengl_lib.path) +GL.load_lib(ENV["MITTSU_LIBGL_PATH"] || opengl_lib.path, Mittsu.debug?) require 'mittsu/renderers/glfw_window' require 'mittsu/renderers/opengl/opengl_debug' if ENV['DEBUG'] diff --git a/test/renderers/opengl/test_opengl_lib.rb b/test/renderers/opengl/test_opengl_lib.rb index a35b4578..7f836b8d 100644 --- a/test/renderers/opengl/test_opengl_lib.rb +++ b/test/renderers/opengl/test_opengl_lib.rb @@ -2,7 +2,7 @@ class TestOpenGLLib < Minitest::Test def test_linux_64_nvidia_1 - fake_loader = Struct.new(:libgl_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( + fake_loader = Struct.new(:lib_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( [ '/usr/lib/x86_64-linux-gnu/mesa/libGL.so', '/usr/lib/x86_64-linux-gnu/libGL.so', @@ -13,13 +13,12 @@ def test_linux_64_nvidia_1 ) linux_lib = Mittsu::OpenGLLib::Linux.new(fake_loader) - assert_equal 'libGL.so', linux_lib.file - assert_equal '/usr/lib/x86_64-linux-gnu', linux_lib.path + assert_equal '/usr/lib/x86_64-linux-gnu/libGL.so', linux_lib.path end # TODO: get real test data from my nvidia PC when I get home def test_linux_64_nvidia_2 - fake_loader = Struct.new(:libgl_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( + fake_loader = Struct.new(:lib_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( [ '/usr/lib/x86_64-linux-gnu/libGL.so', '/usr/lib/x86_64-linux-gnu/mesa/libGL.so', @@ -32,12 +31,11 @@ def test_linux_64_nvidia_2 ) linux_lib = Mittsu::OpenGLLib::Linux.new(fake_loader) - assert_equal 'libGL.so', linux_lib.file - assert_equal '/usr/lib/nvidia-367', linux_lib.path + assert_equal '/usr/lib/nvidia-367/libGL.so', linux_lib.path end def test_linux_64_vboxvideo - fake_loader = Struct.new(:libgl_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( + fake_loader = Struct.new(:lib_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( [ '/usr/lib/x86_64-linux-gnu/mesa/libGL.so', '/usr/lib/x86_64-linux-gnu/libGL.so' @@ -48,12 +46,11 @@ def test_linux_64_vboxvideo ) linux_lib = Mittsu::OpenGLLib::Linux.new(fake_loader) - assert_equal 'libGL.so', linux_lib.file - assert_equal '/usr/lib/x86_64-linux-gnu', linux_lib.path + assert_equal '/usr/lib/x86_64-linux-gnu/libGL.so', linux_lib.path end def test_linux_64_ldconfig - fake_loader = Struct.new(:libgl_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( + fake_loader = Struct.new(:lib_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( [], '', true, @@ -67,12 +64,11 @@ def test_linux_64_ldconfig ) linux_lib = Mittsu::OpenGLLib::Linux.new(fake_loader) - assert_equal 'libGL.so.1', linux_lib.file - assert_equal '/usr/lib/nvidia-367', linux_lib.path + assert_equal '/usr/lib/nvidia-367/libGL.so.1', linux_lib.path end def test_linux_32_ldconfig - fake_loader = Struct.new(:libgl_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( + fake_loader = Struct.new(:lib_paths, :kernel_module_in_use, :sixtyfour_bits?, :ldconfig).new( [], '', false, @@ -86,8 +82,7 @@ def test_linux_32_ldconfig ) linux_lib = Mittsu::OpenGLLib::Linux.new(fake_loader) - assert_equal 'libGL.so.1', linux_lib.file - assert_equal '/usr/lib32/nvidia-367', linux_lib.path + assert_equal '/usr/lib32/nvidia-367/libGL.so.1', linux_lib.path end # TODO: get real-world data for 32-bit machines, as well as neuvaux, fglrx, radeon, and intel configs