Class: GL::Spec
- Inherits:
-
Object
- Object
- GL::Spec
- 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
-
#api ⇒ Symbol
readonly
The OpenGL API name.
-
#extensions ⇒ Array<String>
readonly
An array of extension names.
-
#profile ⇒ Symbol
readonly
The OpenGL profile name for the specification.
-
#registry ⇒ Registry
The registry instance the specification uses for reference.
-
#version ⇒ String
readonly
The OpenGL version number for the specification.
Instance Method Summary collapse
-
#enums ⇒ Array<Registry::Enum>
Retrieves a complete list of all OpenGL enumeration values that this specification defines.
-
#functions ⇒ Array<Registry::Function>
Retrieves a complete list of all OpenGL functions that this specification defines.
-
#initialize(registry, api, version, profile, *extensions) ⇒ Spec
constructor
Creates a new instance of the Spec class.
-
#to_s ⇒ String
The string representation of this object.
-
#types(groups = false) ⇒ Array<Symbol>
Retrieves a complete list of all OpenGL types that this specification must have defined.
-
#used_groups ⇒ Array<String>
Retrieves a complete list of all OpenGL group names that this specification uses.
Constructor Details
#initialize(registry, api, version, profile, *extensions) ⇒ Spec
Creates a new instance of the GL::Spec class.
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
#api ⇒ Symbol (readonly)
Returns the OpenGL API name.
16 17 18 |
# File 'lib/opengl/spec.rb', line 16 def api @api end |
#extensions ⇒ Array<String> (readonly)
Returns an array of extension names.
28 29 30 |
# File 'lib/opengl/spec.rb', line 28 def extensions @extensions end |
#profile ⇒ Symbol (readonly)
Returns the OpenGL profile name for the specification.
24 25 26 |
# File 'lib/opengl/spec.rb', line 24 def profile @profile end |
#registry ⇒ Registry
Returns the registry instance the specification uses for reference.
12 13 14 |
# File 'lib/opengl/spec.rb', line 12 def registry @registry end |
#version ⇒ String (readonly)
Returns the OpenGL version number for the specification.
20 21 22 |
# File 'lib/opengl/spec.rb', line 20 def version @version end |
Instance Method Details
#enums ⇒ Array<Registry::Enum>
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.
86 87 88 |
# File 'lib/opengl/spec.rb', line 86 def enums items(:enum, @registry.enums) end |
#functions ⇒ Array<Registry::Function>
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.
77 78 79 |
# File 'lib/opengl/spec.rb', line 77 def functions items(:function, @registry.functions) end |
#to_s ⇒ String
Returns 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>
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.
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_groups ⇒ Array<String>
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.
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 |