Module: WGPU::Native::OptionalFunctions

Included in:
WGPU::Native
Defined in:
lib/wgpu/native/loader.rb

Instance Method Summary collapse

Instance Method Details

#attach_optional_function(name, arguments, result) ⇒ void

This method returns an undefined value.

Attaches a native function without failing library initialization.

Parameters:

  • name (Symbol)

    exported function name

  • arguments (Array)

    FFI argument types

  • result (Symbol, FFI::Type)

    FFI return type



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/wgpu/native/loader.rb', line 15

def attach_optional_function(name, arguments, result)
  attach_function(name, arguments, result)
  optional_functions[name] = true
rescue FFI::NotFoundError
  optional_functions[name] = false
  define_singleton_method(name) do |*|
    raise WGPU::Error,
      "Optional wgpu-native function #{name} is unavailable in the loaded library " \
      "(expected #{Distribution::VERSION})"
  end
end

#optional_capabilitiesHash{Symbol => Boolean}

Returns availability information for optional native functions.

Returns:

  • (Hash{Symbol => Boolean})

    immutable capability snapshot



37
38
39
# File 'lib/wgpu/native/loader.rb', line 37

def optional_capabilities
  optional_functions.dup.freeze
end

#optional_function_available?(name) ⇒ Boolean

Reports whether an optional native function was attached.

Parameters:

  • name (Symbol)

    exported function name

Returns:

  • (Boolean)


30
31
32
# File 'lib/wgpu/native/loader.rb', line 30

def optional_function_available?(name)
  optional_functions.fetch(name, false)
end