Class: GL::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/opengl/spec.rb

Overview

Describes a specific subset of the OpenGL registry, targeting an API, version, profile, etc.

Automatically filters all results bu the specified criteria, only returning results that are used in the specification.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry, api, version, profile, *extensions) ⇒ Spec

Creates a new instance of the GL::Spec class.

Parameters:

  • registry (Registry)

    An registry instance to use for definition referencing.

  • api (Symbol, String)

    The OpenGL API name.

  • version (String, Float)

    The OpenGL version number for the specification.

  • profile (Symbol, String)

    The OpenGL profile name for the specification.

  • extensions (Array<String>)

    Names of extensions name to include definitions for.



38
39
40
41
42
43
44
# File 'lib/opengl/spec.rb', line 38

def initialize(registry, api, version, profile, *extensions)
  @registry = registry
  @api = api.to_sym
  @profile = profile.to_sym
  @version = Float(version).to_s
  @extensions = extensions&.uniq || []
end

Instance Attribute Details

#apiSymbol (readonly)

Returns the OpenGL API name.

Returns:

  • (Symbol)

    the OpenGL API name.



16
17
18
# File 'lib/opengl/spec.rb', line 16

def api
  @api
end

#extensionsArray<String> (readonly)

Returns an array of extension names.

Returns:

  • (Array<String>)

    an array of extension names.



28
29
30
# File 'lib/opengl/spec.rb', line 28

def extensions
  @extensions
end

#profileSymbol (readonly)

Returns the OpenGL profile name for the specification.

Returns:

  • (Symbol)

    the OpenGL profile name for the specification.



24
25
26
# File 'lib/opengl/spec.rb', line 24

def profile
  @profile
end

#registryRegistry

Returns the registry instance the specification uses for reference.

Returns:

  • (Registry)

    the registry instance the specification uses for reference.



12
13
14
# File 'lib/opengl/spec.rb', line 12

def registry
  @registry
end

#versionString (readonly)

Returns the OpenGL version number for the specification.

Returns:

  • (String)

    the OpenGL version number for the specification.



20
21
22
# File 'lib/opengl/spec.rb', line 20

def version
  @version
end

Instance Method Details

#enumsArray<Registry::Enum>

Note:

The values are re-calculated each time this method is invoked, so consider caching the result if reusing.

Retrieves a complete list of all OpenGL enumeration values that this specification defines.

Returns:



86
87
88
# File 'lib/opengl/spec.rb', line 86

def enums
  items(:enum, @registry.enums)
end

#functionsArray<Registry::Function>

Note:

The values are re-calculated each time this method is invoked, so consider caching the result if reusing.

Retrieves a complete list of all OpenGL functions that this specification defines.

Returns:



77
78
79
# File 'lib/opengl/spec.rb', line 77

def functions
  items(:function, @registry.functions)
end

#to_sString

Returns the string representation of this object.

Returns:

  • (String)

    the string representation of this object.



113
114
115
116
117
118
# File 'lib/opengl/spec.rb', line 113

def to_s
  if profile != :none
    return "Open#{@api.to_s.upcase} #{@version} (#{@profile} profile)"
  end
  "Open#{@api.to_s.upcase} #{@version}"
end

#types(groups = false) ⇒ Array<Symbol>

Note:

The values are re-calculated each time this method is invoked, so consider caching the result if reusing.

Retrieves a complete list of all OpenGL types that this specification must have defined. Any type not included here does not need to be mapped.

Parameters:

  • groups (Boolean) (defaults to: false)

    true to include group (enumeration) names, otherwise false

Returns:

  • (Array<Symbol>)

    a collection of OpenGL types.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/opengl/spec.rb', line 54

def types(groups = false)

  values = {}
  functions.each do |func|

    values[func.type.base] = true
    values[func.type.group] = true if groups && func.type.group

    func.arguments.each do |arg|
      values[arg.type.base] = true
      values[arg.type.group] = true if groups && arg.type.group
    end
  end

  #noinspection RubyYardReturnMatch
  values.keys.map(&:to_sym)
end

#used_groupsArray<String>

Note:

The values are re-calculated each time this method is invoked, so consider caching the result if reusing.

Retrieves a complete list of all OpenGL group names that this specification uses.

Returns:

  • (Array<String>)

    a collection of group (enumeration) names.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/opengl/spec.rb', line 95

def used_groups

  names = {}
  functions.each do |func|

    names[func.type.group] = true if func.type.group
    func.arguments.each do |arg|
      group = arg.type.group
      next unless group

      names[group] = true
    end
  end
  names.keys
end