opengl-registry 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+ module GL
2
+ class Registry
3
+
4
+ ##
5
+ # Describes an individual argument of an OpenGL function.
6
+ class Argument < Token
7
+
8
+ ##
9
+ # @return [String] the name of the argument
10
+ attr_reader :name
11
+
12
+ ##
13
+ # @return [NativeType] the type of the argument.
14
+ attr_reader :type
15
+
16
+ ##
17
+ # @return [String?] a hint for any length constraints of an argument, such as a C-style array,
18
+ # @note This may be a numerical value, reference to another "count" argument, etc.
19
+ attr_reader :length
20
+
21
+ ##
22
+ # Creates a new instance of the {Argument} class.
23
+ #
24
+ # @param node [Ox::Element] The XML element defining the instance.
25
+ def initialize(node)
26
+ super(node)
27
+
28
+ base = nil
29
+ buffer = ''
30
+ node.nodes.each do |child|
31
+
32
+ # Don't care about comments
33
+ next if child.is_a?(Ox::Comment)
34
+
35
+ # Raw text
36
+ if child.is_a?(String)
37
+ buffer << child
38
+ next
39
+ end
40
+
41
+ # Child node
42
+ case child.name
43
+ when Words::PTYPE
44
+ base = child.text
45
+ buffer << base
46
+ when Words::NAME
47
+ @name = child.text
48
+ else
49
+ next
50
+ end
51
+ end
52
+
53
+ @length = node[Words::LENGTH]
54
+ group = node[Words::GROUP]
55
+ @type = NativeType.new(buffer, base, group)
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+ module GL
3
+
4
+ class Registry
5
+
6
+ ##
7
+ # Describes an OpenGL enumeration (constant) value.
8
+ class Enum < Token
9
+
10
+ ##
11
+ # @return [String] the name of the enumeration member.
12
+ attr_reader :name
13
+
14
+ ##
15
+ # @return [String] the value of the enumeration, always numerical, typically in hexadecimal format.
16
+ attr_reader :value
17
+
18
+ ##
19
+ # @return [String?] an alternative name for the value.
20
+ attr_reader :alias_name
21
+
22
+ ##
23
+ # @return [Symbol] a hint for the enumeration value type (i.e. GLenum, GLuint, GLuint64, etc)
24
+ attr_reader :type
25
+
26
+ ##
27
+ # @return [Symbol?] an API associated with this enumeration value.
28
+ attr_reader :api
29
+
30
+ ##
31
+ # @return [Array<String>] an array of names of the groups this enumeration is defined within.
32
+ attr_reader :groups
33
+
34
+ ##
35
+ # Creates a new instance of the {Enum} class.
36
+ #
37
+ # @param node [Ox::Element] The XML element defining the instance.
38
+ def initialize(node)
39
+ super(node)
40
+
41
+ # Required
42
+ @name = node[Words::NAME]
43
+ @value = node[Words::VALUE]
44
+
45
+ # Optional
46
+ @alias_name = node[Words::ALIAS]
47
+ @api = node[Words::API]&.to_sym
48
+ @groups = node[Words::GROUP]&.split(',') || []
49
+
50
+ @type = case node[Words::TYPE]
51
+ when Words::U_LONG then :GLuint
52
+ when Words::U_LONG_LONG then :GLuint64
53
+ else :GLenum
54
+ end
55
+ end
56
+
57
+ ##
58
+ # @return [Integer] the enumeration's value, as an integer.
59
+ def to_i
60
+ @value.start_with?('0x') ? @value.hex : @value.to_i
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,23 @@
1
+ module GL
2
+ class Registry
3
+
4
+ ##
5
+ # Describes an OpenGL extension.
6
+ class Extension < FeatureProvider
7
+
8
+ ##
9
+ # @return [Array<Symbol>] an array of supported APIs this extension is associated with.
10
+ attr_reader :supported
11
+
12
+ ##
13
+ # Creates a new instance of the {Extension} class.
14
+ #
15
+ # @param node [Ox::Element] The XML element defining the instance.
16
+ def initialize(node)
17
+ super(node)
18
+ supported = node[Words::SUPPORTED]
19
+ @supported = supported ? supported.split('|').map(&:to_sym) : Array.new
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ module GL
2
+ class Registry
3
+
4
+ ##
5
+ # Describes a single definition of a item to add/remove from an OpenGL API.
6
+ #
7
+ # @note This is a reference for the item only, and is only used to look up the corresponding item's definition.
8
+ class Feature < Token
9
+
10
+ ##
11
+ # @return [String] the name of the entity.
12
+ attr_reader :name
13
+
14
+ ##
15
+ # @return [Symbol] the OpenGL API this item is associated with.
16
+ attr_reader :api
17
+
18
+ ##
19
+ # @return [Symbol] the OpenGL profile this item is associated with.
20
+ attr_reader :profile
21
+
22
+ ##
23
+ # @return [:enum,:function,:type] a symbol specifying the feature type.
24
+ attr_reader :type
25
+
26
+ ##
27
+ # Creates a new instance of the {Feature} class.
28
+ #
29
+ # @param node [Ox::Element] The XML element defining the instance.
30
+ # @param api [Symbol?] The OpenGL API this item is associated with.
31
+ # @param profile [Symbol?] The OpenGL profile this item is associated with.
32
+ def initialize(node, api, profile)
33
+ super(node)
34
+
35
+ @name = node[Words::NAME]
36
+ @api = api || :none
37
+ @profile = profile || :none
38
+
39
+ @type = case node.name
40
+ when Words::ENUM then :enum
41
+ when Words::COMMAND then :function
42
+ when Words::TYPE then :type
43
+ else :unknown
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ module GL
2
+ class Registry
3
+
4
+ ##
5
+ # Describes a logical grouping of features for an OpenGL API.
6
+ class FeatureGroup < FeatureProvider
7
+
8
+ ##
9
+ # @return [String] the OpenGL version this feature is associated with.
10
+ attr_reader :version
11
+
12
+ ##
13
+ # @return [Array<Feature>] an array of features that this instance removes.
14
+ attr_reader :removals
15
+
16
+ ##
17
+ # Creates a new instance of the {Feature} class.
18
+ #
19
+ # @param node [Ox::Element] The XML element defining the instance.
20
+ def initialize(node)
21
+ super(node)
22
+
23
+ @version = node[Words::NUMBER]
24
+ @removals = []
25
+ node.locate('remove').each do |child|
26
+
27
+ api = child[Words::API]&.to_sym || @api
28
+ profile = child[Words::PROFILE]&.to_sym
29
+
30
+ child.nodes.each do |item|
31
+ next unless item.is_a?(Ox::Element)
32
+ @removals << Feature.new(item, api, profile)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,45 @@
1
+ module GL
2
+ class Registry
3
+
4
+ ##
5
+ # @abstract Base class for objects that add definitions to the API.
6
+ class FeatureProvider < Token
7
+
8
+ ##
9
+ # @return [Symbol] the name of the API this feature is defined within.
10
+ attr_reader :api
11
+
12
+ ##
13
+ # @return [String] the name of the feature set.
14
+ attr_reader :name
15
+
16
+ ##
17
+ # @return [Array<Feature>] an array of features that this instance provides.
18
+ attr_reader :additions
19
+
20
+ ##
21
+ # Creates a new instance of the {FeatureProvider} class.
22
+ #
23
+ # @param node [Ox::Element] The XML element defining the instance.
24
+ def initialize(node)
25
+ super(node)
26
+
27
+ @api = node[Words::API]&.to_sym || :none
28
+ @name = node[Words::NAME]
29
+
30
+ @additions = []
31
+ node.locate('require').each do |child|
32
+
33
+ api = child[Words::API]&.to_sym || @api
34
+ profile = child[Words::PROFILE]&.to_sym
35
+
36
+ child.nodes.each do |item|
37
+ next unless item.is_a?(Ox::Element)
38
+ @additions << Feature.new(item, api, profile)
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,86 @@
1
+ module GL
2
+ class Registry
3
+
4
+ ##
5
+ # Describes an OpenGL function.
6
+ class Function < Token
7
+
8
+ ##
9
+ # @return [String] the name of the function.
10
+ attr_reader :name
11
+
12
+ ##
13
+ # @return [NativeType] the return type of function.
14
+ attr_reader :type
15
+
16
+ ##
17
+ # @return [Array<Argument>] an array of arguments for this function.
18
+ attr_reader :arguments
19
+
20
+ ##
21
+ # @return [String?] an alternative name associated with this function.
22
+ attr_reader :alias_name
23
+
24
+ ##
25
+ # @return [String?] a "vector equivalent" version of this function that does not use separate parameters.
26
+ attr_reader :vec_equiv
27
+
28
+ ##
29
+ # Creates a new instance of the {Function} class.
30
+ #
31
+ # @param node [Ox::Element] The XML element defining the instance.
32
+ def initialize(node)
33
+ super(node)
34
+
35
+ @arguments = []
36
+ node.nodes.each do |child|
37
+
38
+ case child.name
39
+ when Words::PROTO
40
+ parse_prototype(child)
41
+ when Words::PARAM
42
+ @arguments << Argument.new(child)
43
+ when Words::ALIAS
44
+ @alias_name = child[Words::NAME]
45
+ when Words::VECTOR_EQUIVALENT
46
+ @vec_equiv = child[Words::NAME]
47
+ else
48
+ next
49
+ end
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def parse_prototype(node)
56
+ base = nil
57
+ buffer = ''
58
+ node.nodes.each do |child|
59
+
60
+ # Don't care about comments
61
+ next if child.is_a?(Ox::Comment)
62
+
63
+ # Raw text
64
+ if child.is_a?(String)
65
+ buffer << child
66
+ next
67
+ end
68
+
69
+ # Child node
70
+ case child.name
71
+ when Words::PTYPE
72
+ base = child.text
73
+ buffer << base
74
+ when Words::NAME
75
+ @name = child.text
76
+ else
77
+ next
78
+ end
79
+ end
80
+
81
+ group = node[Words::GROUP]
82
+ @type = NativeType.new(buffer, base, group)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,62 @@
1
+ module GL
2
+ class Registry
3
+
4
+ ##
5
+ # Describes a logical grouping of enumerated values.
6
+ class Group < Token
7
+
8
+ ##
9
+ # @return [String] the namespace this group belongs within.
10
+ attr_reader :namespace
11
+
12
+ ##
13
+ # @return [Array<Enum>] an array of enum values that are associated with this group.
14
+ attr_reader :members
15
+
16
+ ##
17
+ # @return [String?] the name of this grouping.
18
+ # @note Not all groups are named, and this value may be `nil`.
19
+ attr_reader :name
20
+
21
+ ##
22
+ # @return [String?] the name of the vendor that defines this value.
23
+ attr_reader :vendor
24
+
25
+ ##
26
+ # @return [Range?] an end-inclusive range of values this group covers.
27
+ attr_reader :range
28
+
29
+ ##
30
+ # Creates a new instance of the {Group} class.
31
+ #
32
+ # @param node [Ox::Element] The XML element defining the instance.
33
+ def initialize(node)
34
+ super(node)
35
+
36
+ @namespace = node[Words::NAMESPACE]
37
+ @name = node[Words::GROUP]
38
+ type = node[Words::TYPE]
39
+ @bitmask = type && type == Words::BITMASK
40
+ @vendor = node[Words::VENDOR]
41
+
42
+ first = node[Words::RANGE_START]
43
+ if first
44
+ last = node[Words::RANGE_END]
45
+ @range = Range.new(first.hex, last.hex, false) if last
46
+ end
47
+
48
+ @members = []
49
+ node.locate('enum').each do |enum|
50
+ next unless enum.is_a?(Ox::Element)
51
+ @members << Enum.new(enum)
52
+ end
53
+ end
54
+
55
+ ##
56
+ # @return [Boolean] `true` if group members are flags that can be bitwise OR'ed together, otherwise `false`.
57
+ def bitmask?
58
+ @bitmask
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,59 @@
1
+
2
+ module GL
3
+ class Registry
4
+
5
+ ##
6
+ # Describes the native type for a return or parameter value.
7
+ class NativeType
8
+
9
+ ##
10
+ # @return [String] the full native type, including constant constraints, pointer symbols, etc.
11
+ # @note This is essentially the "raw" and fully-qualified type as it would appear in the C language.
12
+ attr_reader :type
13
+
14
+ ##
15
+ # @return [Symbol] the basic type, excluding any constant constraints, pointer symbols, etc. as a Symbol.
16
+ attr_reader :base
17
+
18
+ ##
19
+ # @return [String?] a group that is associated with this type.
20
+ attr_reader :group
21
+
22
+ ##
23
+ # Creates a new instance fo the {NativeType} class.
24
+ #
25
+ # @param type [String] The full native type, including constant constraints, pointer symbols, etc.
26
+ # @param base [String?] The basic type, excluding any constant constraints, pointer symbols, etc.
27
+ # @param group [String?] A group that is associated with this type.
28
+ def initialize(type, base, group)
29
+ @type = type.strip
30
+ @base = base ? base.to_sym : :GLvoid
31
+ @group = group
32
+ end
33
+
34
+ ##
35
+ # @return [Boolean] `true` if this a C-style pointer type, otherwise `false`.
36
+ def pointer?
37
+ @type.include?('*')
38
+ end
39
+
40
+ ##
41
+ # @return [Boolean] `true` if value is a C-style pointer that can not be modified, otherwise `false`.
42
+ def const?
43
+ /^const /.match?(@type)
44
+ end
45
+
46
+ ##
47
+ # @return [Boolean] `true` if value is a C-style pointer that may be modified, otherwise `false`.
48
+ def out?
49
+ @type.include?('*') && !/\bconst\b/.match?(@type)
50
+ end
51
+
52
+ ##
53
+ # @return [String] the string representation of this object.
54
+ def to_s
55
+ @type
56
+ end
57
+ end
58
+ end
59
+ end