Class: GL::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/opengl/registry.rb,
lib/opengl/registry/enum.rb,
lib/opengl/registry/group.rb,
lib/opengl/registry/token.rb,
lib/opengl/registry/feature.rb,
lib/opengl/registry/version.rb,
lib/opengl/registry/argument.rb,
lib/opengl/registry/function.rb,
lib/opengl/registry/extension.rb,
lib/opengl/registry/native_type.rb,
lib/opengl/registry/feature_group.rb,
lib/opengl/registry/feature_provider.rb

Overview

Container for all definitions of the OpenGL registry.

Examples:


# Check if registry XML file is up to data
if GL::Registry.outdated?('gl.xml')
  GL::Registry.download('gl.xml')
end

registry = GL::Registry.load('gl.xml')
spec = GL::Spec.new(registry, :gl, 3.3, :core)

# Use "spec" object to enumerate over detailed objects defining each token

Defined Under Namespace

Classes: Argument, Enum, Extension, Feature, FeatureGroup, FeatureProvider, Function, Group, NativeType, Token

Constant Summary collapse

GL_TYPES =

An array of OpenGL type names, as symbols.

%i[
  GLenum GLboolean GLbitfield GLvoid GLbyte GLubyte GLshort GLushort GLint
  GLuint GLclampx GLsizei GLfloat GLclampf GLdouble GLclampd
  GLeglClientBufferEXT GLeglImageOES GLchar GLhandleARB GLhalf GLhalfARB
  GLfixed GLintptr GLintptrARB GLsizeiptr GLsizeiptrARB GLint64 GLint64EXT
  GLuint64 GLuint64EXT GLsync struct\ _cl_context struct\ _cl_event
  GLDEBUGPROC GLDEBUGPROCARB GLDEBUGPROCKHR GLDEBUGPROCAMD GLhalfNV
  GLvdpauSurfaceNV GLVULKANPROCNV
].freeze
VERSION =

The current version of the opengl-registry gem.

'1.0.1'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enumsArray<Enum> (readonly)

Returns a complete collection of all OpenGL enum values.

Returns:

  • (Array<Enum>)

    a complete collection of all OpenGL enum values.



# File 'lib/opengl/registry.rb', line 68

#extensionsArray<Extension> (readonly)

Returns a complete collection of all OpenGL extensions.

Returns:

  • (Array<Extension>)

    a complete collection of all OpenGL extensions.



78
79
80
# File 'lib/opengl/registry.rb', line 78

def extensions
  @extensions
end

#featuresArray<FeatureGroup> (readonly)

Returns a complete collection of all OpenGL feature groups.

Returns:

  • (Array<FeatureGroup>)

    a complete collection of all OpenGL feature groups.



74
75
76
# File 'lib/opengl/registry.rb', line 74

def features
  @features
end

#functionsArray<Function> (readonly)

Returns a complete collection of all OpenGL functions.

Returns:

  • (Array<Function>)

    a complete collection of all OpenGL functions.



66
67
68
# File 'lib/opengl/registry.rb', line 66

def functions
  @functions
end

#groupsArray<Group> (readonly)

Note:

This is for reference only, and should not be used for building definitions or determining a comprehensive list of which enum values belong in each group, use the GL::Registry::Enum#groups property instead.

Returns a collection of all enumeration groups defined by OpenGL.

Returns:

  • (Array<Group>)

    a collection of all enumeration groups defined by OpenGL.



62
63
64
# File 'lib/opengl/registry.rb', line 62

def groups
  @groups
end

Class Method Details

.download(path) ⇒ Boolean

Download the latest version of the OpenGL registry to the specified file.

Parameters:

  • path (String)

    The path where the file will be saved.

Returns:

  • (Boolean)

    true on success, otherwise false if an error occurred.



237
238
239
240
241
242
243
244
245
246
# File 'lib/opengl/registry.rb', line 237

def self.download(path)
  begin
    URI.open('https://raw.githubusercontent.com/KhronosGroup/OpenGL-Registry/master/xml/gl.xml') do |io|
      FileUtils.mv(io.path, path)
    end
    return true
  rescue
    return false
  end
end

.load(path) ⇒ Registry

Creates a new GL::Registry from the specified XML file.

Parameters:

  • path (String)

    The path to the registry file.

Returns:



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

def self.load(path)
  doc = Ox.load_file(path, mode: :generic)
  new(doc.root)
end

.outdated?(path) ⇒ Boolean

Note:

This method is not guaranteed to be accurate, it only uses the timestamps in the file's metadata, which could be inaccurate due to file copying, system time changes, creating from different source, etc.

Compares the registry at the specified path to the current registry version and returns value indicating if there is a newer version available.

Parameters:

  • path (String)

    The path to a registry file to test.

Returns:

  • (Boolean)

    true if a newer version is available, otherwise false if file is current and/or an error occurred.



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/opengl/registry.rb', line 259

def self.outdated?(path)

  return false unless path && File.exist?(path)

  begin
    uri = URI('https://api.github.com/repos/KhronosGroup/OpenGL-Registry/commits?path=xml/gl.xml')
    Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 3, read_timeout: 5) do |http|

      req = Net::HTTP::Get.new(uri)
      response = http.request(req)

      if response.code == '200'
        json = JSON.parse(response.body, symbolize_names: true)
        commit = DateTime.parse(json.first[:commit][:author][:date]).to_time
        return File.mtime(path) < commit
      end

    end
  rescue
    warn('failed to query current registry version')
    return false
  end
end

.parse(xml) ⇒ Registry

Creates a new GL::Registry from the specified XML string.

Parameters:

  • xml (String)

    The OpenGL registry as an XML string.

Returns:



97
98
99
100
# File 'lib/opengl/registry.rb', line 97

def self.parse(xml)
  doc = Ox.load(xml, mode: :generic)
  new(doc.root)
end

Instance Method Details

#api_namesArray<Symbol>

Returns an array of Symbol objects that represent each defined API in the registry.

Returns:

  • (Array<Symbol>)

    an array of Symbol objects that represent each defined API in the registry.



104
105
106
107
108
# File 'lib/opengl/registry.rb', line 104

def api_names
  # RubyMine warns that the return value is wrong. It lies.
  #noinspection RubyYardReturnMatch
  @features.map(&:api).uniq
end

#each_enumEnumerator #each_enum {|enum| ... } ⇒ void

Enumerates through each enum defined in the registry.

Overloads:

  • #each_enumEnumerator

    When called without a block, returns an Enumerator.

    Returns:

    • (Enumerator)

      An enum enumerator.

  • #each_enum {|enum| ... } ⇒ void

    This method returns an undefined value.

    When called with a block, yields each item to the block and returns nil.

    Yield Parameters:

    • enum (Enum)

      Yields an enum to the block.



150
151
152
153
154
155
156
157
# File 'lib/opengl/registry.rb', line 150

def each_enum
  #noinspection RubyYardReturnMatch
  return enum_for(__method__) unless block_given?
  @groups.each do |group|
    group.members.each { |item| yield item }
  end
  nil
end

#each_enumEnumerator #each_enum {|enum| ... } ⇒ void

Enumerates through each extension defined in the registry.

Overloads:

  • #each_enumEnumerator

    When called without a block, returns an Enumerator.

    Returns:

    • (Enumerator)

      An extension enumerator.

  • #each_enum {|enum| ... } ⇒ void

    This method returns an undefined value.

    When called with a block, yields each item to the block and returns nil.

    Yield Parameters:

    • enum (Extension)

      Yields an extension to the block.



224
225
226
227
228
229
# File 'lib/opengl/registry.rb', line 224

def each_extension
  #noinspection RubyYardReturnMatch
  return enum_for(__method__) unless block_given?
  @extensions.each { |item| yield item }
  nil
end

#each_featureEnumerator #each_feature {|enum| ... } ⇒ void

Enumerates through each feature group defined in the registry.

Overloads:

  • #each_featureEnumerator

    When called without a block, returns an Enumerator.

    Returns:

    • (Enumerator)

      A feature group enumerator.

  • #each_feature {|enum| ... } ⇒ void

    This method returns an undefined value.

    When called with a block, yields each item to the block and returns nil.

    Yield Parameters:



206
207
208
209
210
211
# File 'lib/opengl/registry.rb', line 206

def each_feature
  #noinspection RubyYardReturnMatch
  return enum_for(__method__) unless block_given?
  @features.each { |item| yield item }
  nil
end

#each_functionEnumerator #each_function {|enum| ... } ⇒ void

Enumerates through each function defined in the registry.

Overloads:

  • #each_functionEnumerator

    When called without a block, returns an Enumerator.

    Returns:

    • (Enumerator)

      A function enumerator.

  • #each_function {|enum| ... } ⇒ void

    This method returns an undefined value.

    When called with a block, yields each item to the block and returns nil.

    Yield Parameters:

    • enum (Function)

      Yields a function to the block.



188
189
190
191
192
193
# File 'lib/opengl/registry.rb', line 188

def each_function
  #noinspection RubyYardReturnMatch
  return enum_for(__method__) unless block_given?
  @functions.each { |item| yield item }
  nil
end

#each_groupEnumerator #each_group {|group| ... } ⇒ void

Enumerates through each group defined in the registry.

Overloads:

  • #each_groupEnumerator

    When called without a block, returns an Enumerator.

    Returns:

    • (Enumerator)

      A group enumerator.

  • #each_group {|group| ... } ⇒ void

    This method returns an undefined value.

    When called with a block, yields each item to the block and returns nil.

    Yield Parameters:

    • group (Group)

      Yields a group to the block.



170
171
172
173
174
175
# File 'lib/opengl/registry.rb', line 170

def each_group
  #noinspection RubyYardReturnMatch
  return enum_for(__method__) unless block_given?
  @groups.each { |item| yield item }
  nil
end

#profilesArray<Symbol> #profiles(api) ⇒ Array<Symbol> #profiles(api, version) ⇒ Array<Symbol>

Retrieves an array of profiles defined in the registry.

Overloads:

  • #profiles(api) ⇒ Array<Symbol>

    Parameters:

    • api (Symbol)

      An API to limit results to a specific API.

  • #profiles(api, version) ⇒ Array<Symbol>

    Parameters:

    • api (Symbol)

      An API to limit results to a specific API.

    • version (String|Float)

      A version to limit results to.

Returns:

  • (Array<Symbol>)

    an array of defined profiles.



123
124
125
126
127
128
129
130
131
132
# File 'lib/opengl/registry.rb', line 123

def profiles(api = nil, version = '1.0')
  # RubyMine warns that the return value is wrong. It lies.
  if api
    values = @features.find_all { |group| group.api == api && group.version <= version.to_s }
    #noinspection RubyYardReturnMatch
    return values.flat_map(&:additions).map(&:profile).uniq
  end
  #noinspection RubyYardReturnMatch
  @features.flat_map(&:additions).map(&:profile).uniq
end