Sha256: dcb2a48ea9ce8be1676b74443431483e5a39cf40387c715f2029750595863b8e

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

module OpenGLLib
  def self.discover
    case OpenGL.get_platform
    when :OPENGL_PLATFORM_WINDOWS
      Windows.new
    when :OPENGL_PLATFORM_MACOSX
      MacOS.new
    when :OPENGL_PLATFORM_LINUX
      Linux.new
    else
      fail "Unsupported platform."
    end
  end

  class Linux
    def path
      # http://www.pilotlogic.com/sitejoom/index.php/wiki?id=398<F37>
      # 32              64
      # /usr/lib        /usr/lib64       redhat, mandriva
      # /usr/lib32      /usr/lib64       arch, gento
      # /usr/lib        /usr/lib64       slackware
      # /usr/lib/i386.. /usr/libx86_64/  debian
      libs = Dir.glob("/usr/lib*/**/libGL.so")
      if libs.size == 0
        puts "no libGL.so"
        exit 1
      end
      case kernel_module_in_use
      when /nvidia/
        return File.dirname(libs.grep(/nvidia/)[0])
      end
      # Get the same architecture that the runnning ruby
      if 1.size == 8 # 64 bits
        File.dirname(libs.grep(/64/)[0])
      else # 32 bits
        File.dirname(libs[0])
      end
    end

    def file
      'libGL.so'
    end

    private
      def kernel_module_in_use
        lspci_line = `lspci -nnk | grep -i vga -A3 | grep 'in use'`
        return /in use:\s*(\S+)/ =~ lspci_line && $1
      end
  end

  # TODO
  class Windows
    def path; nil; end
    def file; nil; end
  end

  # TODO
  class MacOS
    def path; nil; end
    def file; nil; end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mittsu-0.1.3 lib/mittsu/renderers/opengl/opengl_lib.rb