openxr 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/openxr/abi.rb +181 -13
- data/lib/openxr/extension.rb +5 -3
- data/lib/openxr/instance.rb +4 -3
- data/lib/openxr/result.rb +39 -5
- data/lib/openxr/session.rb +49 -1
- data/lib/openxr/system.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea8d29e0d02b44041b5d016b93a9c8810c97b4425b177188847389bba7a2152d
|
4
|
+
data.tar.gz: fbb249f553c311af5eb20cdc1384501342c130b55a79afac00c91d92491e7d54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce55aa8d35b0c48f77090c3510e893468906e6db83e1f90aa3e4f5740d654f252a83bcfbc1abcdfc68617cd8a71701b66bd0c7e08b15004259b5c6bfe79e4462
|
7
|
+
data.tar.gz: 07ea698336529bd7bdcc6acaba27b695b1cca86e4c2aaca7275dc31611c8e0dce205511b41580c41c089ea2dcc2f28aac864f403df6805a4f3257839c4f5b5ce
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/openxr/abi.rb
CHANGED
@@ -5,6 +5,24 @@ require 'ffi'
|
|
5
5
|
##
|
6
6
|
# The OpenXR application binary interface (ABI).
|
7
7
|
module OpenXR::ABI
|
8
|
+
# @private
|
9
|
+
module InitializeWithType
|
10
|
+
def self.included(klass)
|
11
|
+
##
|
12
|
+
# @param [FFI::AbstractMemory] pointer
|
13
|
+
def initialize(pointer = nil)
|
14
|
+
super(pointer)
|
15
|
+
self.set_type! if pointer.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# @return [void]
|
20
|
+
def set_type!
|
21
|
+
self[:base][:type] = self.class.const_get(:TYPE)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
8
26
|
##
|
9
27
|
# @see https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#api-version-numbers-and-semantics
|
10
28
|
def self.XR_MAKE_VERSION(major, minor, patch)
|
@@ -64,21 +82,155 @@ module OpenXR::ABI
|
|
64
82
|
XR_MAX_LOCALIZED_ACTION_NAME_SIZE = 128
|
65
83
|
|
66
84
|
XrResult = :int # enum
|
67
|
-
XR_SUCCESS
|
68
|
-
|
69
|
-
|
70
|
-
|
85
|
+
XR_SUCCESS = 0
|
86
|
+
XR_TIMEOUT_EXPIRED = 1
|
87
|
+
XR_SESSION_LOSS_PENDING = 3
|
88
|
+
XR_EVENT_UNAVAILABLE = 4
|
89
|
+
XR_SPACE_BOUNDS_UNAVAILABLE = 7
|
90
|
+
XR_SESSION_NOT_FOCUSED = 8
|
91
|
+
XR_FRAME_DISCARDED = 9
|
92
|
+
XR_ERROR_VALIDATION_FAILURE = -1
|
93
|
+
XR_ERROR_RUNTIME_FAILURE = -2
|
94
|
+
XR_ERROR_OUT_OF_MEMORY = -3
|
95
|
+
XR_ERROR_API_VERSION_UNSUPPORTED = -4
|
96
|
+
XR_ERROR_INITIALIZATION_FAILED = -6
|
97
|
+
XR_ERROR_FUNCTION_UNSUPPORTED = -7
|
98
|
+
XR_ERROR_FEATURE_UNSUPPORTED = -8
|
99
|
+
XR_ERROR_EXTENSION_NOT_PRESENT = -9
|
100
|
+
XR_ERROR_LIMIT_REACHED = -10
|
101
|
+
XR_ERROR_SIZE_INSUFFICIENT = -11
|
102
|
+
XR_ERROR_HANDLE_INVALID = -12
|
103
|
+
XR_ERROR_INSTANCE_LOST = -13
|
104
|
+
XR_ERROR_SESSION_RUNNING = -14
|
105
|
+
XR_ERROR_SESSION_NOT_RUNNING = -16
|
106
|
+
XR_ERROR_SESSION_LOST = -17
|
107
|
+
XR_ERROR_SYSTEM_INVALID = -18
|
108
|
+
XR_ERROR_PATH_INVALID = -19
|
109
|
+
XR_ERROR_PATH_COUNT_EXCEEDED = -20
|
110
|
+
XR_ERROR_PATH_FORMAT_INVALID = -21
|
111
|
+
XR_ERROR_PATH_UNSUPPORTED = -22
|
112
|
+
XR_ERROR_LAYER_INVALID = -23
|
113
|
+
XR_ERROR_LAYER_LIMIT_EXCEEDED = -24
|
114
|
+
XR_ERROR_SWAPCHAIN_RECT_INVALID = -25
|
115
|
+
XR_ERROR_SWAPCHAIN_FORMAT_UNSUPPORTED = -26
|
116
|
+
XR_ERROR_ACTION_TYPE_MISMATCH = -27
|
117
|
+
XR_ERROR_SESSION_NOT_READY = -28
|
118
|
+
XR_ERROR_SESSION_NOT_STOPPING = -29
|
119
|
+
XR_ERROR_TIME_INVALID = -30
|
120
|
+
XR_ERROR_REFERENCE_SPACE_UNSUPPORTED = -31
|
121
|
+
XR_ERROR_FILE_ACCESS_ERROR = -32
|
122
|
+
XR_ERROR_FILE_CONTENTS_INVALID = -33
|
123
|
+
XR_ERROR_FORM_FACTOR_UNSUPPORTED = -34
|
124
|
+
XR_ERROR_FORM_FACTOR_UNAVAILABLE = -35
|
125
|
+
XR_ERROR_API_LAYER_NOT_PRESENT = -36
|
126
|
+
XR_ERROR_CALL_ORDER_INVALID = -37
|
127
|
+
XR_ERROR_GRAPHICS_DEVICE_INVALID = -38
|
128
|
+
XR_ERROR_POSE_INVALID = -39
|
129
|
+
XR_ERROR_INDEX_OUT_OF_RANGE = -40
|
130
|
+
XR_ERROR_VIEW_CONFIGURATION_TYPE_UNSUPPORTED = -41
|
131
|
+
XR_ERROR_ENVIRONMENT_BLEND_MODE_UNSUPPORTED = -42
|
132
|
+
XR_ERROR_NAME_DUPLICATED = -44
|
133
|
+
XR_ERROR_NAME_INVALID = -45
|
134
|
+
XR_ERROR_ACTIONSET_NOT_ATTACHED = -46
|
135
|
+
XR_ERROR_ACTIONSETS_ALREADY_ATTACHED = -47
|
136
|
+
XR_ERROR_LOCALIZED_NAME_DUPLICATED = -48
|
137
|
+
XR_ERROR_LOCALIZED_NAME_INVALID = -49
|
138
|
+
XR_ERROR_ANDROID_THREAD_SETTINGS_ID_INVALID_KHR = -1000003000
|
139
|
+
XR_ERROR_ANDROID_THREAD_SETTINGS_FAILURE_KHR = -1000003001
|
140
|
+
XR_ERROR_CREATE_SPATIAL_ANCHOR_FAILED_MSFT = -1000039001
|
141
|
+
XR_RESULT_MAX_ENUM = 0x7FFFFFFF
|
71
142
|
|
72
143
|
XrStructureType = :int # enum
|
73
|
-
XR_TYPE_UNKNOWN
|
74
|
-
XR_TYPE_API_LAYER_PROPERTIES
|
75
|
-
XR_TYPE_EXTENSION_PROPERTIES
|
76
|
-
XR_TYPE_INSTANCE_CREATE_INFO
|
77
|
-
XR_TYPE_SYSTEM_GET_INFO
|
78
|
-
XR_TYPE_SYSTEM_PROPERTIES
|
79
|
-
XR_TYPE_VIEW_LOCATE_INFO
|
80
|
-
XR_TYPE_VIEW
|
81
|
-
XR_TYPE_SESSION_CREATE_INFO
|
144
|
+
XR_TYPE_UNKNOWN = 0
|
145
|
+
XR_TYPE_API_LAYER_PROPERTIES = 1
|
146
|
+
XR_TYPE_EXTENSION_PROPERTIES = 2
|
147
|
+
XR_TYPE_INSTANCE_CREATE_INFO = 3
|
148
|
+
XR_TYPE_SYSTEM_GET_INFO = 4
|
149
|
+
XR_TYPE_SYSTEM_PROPERTIES = 5
|
150
|
+
XR_TYPE_VIEW_LOCATE_INFO = 6
|
151
|
+
XR_TYPE_VIEW = 7
|
152
|
+
XR_TYPE_SESSION_CREATE_INFO = 8
|
153
|
+
XR_TYPE_SWAPCHAIN_CREATE_INFO = 9
|
154
|
+
XR_TYPE_SESSION_BEGIN_INFO = 10
|
155
|
+
XR_TYPE_VIEW_STATE = 11
|
156
|
+
XR_TYPE_FRAME_END_INFO = 12
|
157
|
+
XR_TYPE_HAPTIC_VIBRATION = 13
|
158
|
+
XR_TYPE_EVENT_DATA_BUFFER = 16
|
159
|
+
XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING = 17
|
160
|
+
XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED = 18
|
161
|
+
XR_TYPE_ACTION_STATE_BOOLEAN = 23
|
162
|
+
XR_TYPE_ACTION_STATE_FLOAT = 24
|
163
|
+
XR_TYPE_ACTION_STATE_VECTOR2F = 25
|
164
|
+
XR_TYPE_ACTION_STATE_POSE = 27
|
165
|
+
XR_TYPE_ACTION_SET_CREATE_INFO = 28
|
166
|
+
XR_TYPE_ACTION_CREATE_INFO = 29
|
167
|
+
XR_TYPE_INSTANCE_PROPERTIES = 32
|
168
|
+
XR_TYPE_FRAME_WAIT_INFO = 33
|
169
|
+
XR_TYPE_COMPOSITION_LAYER_PROJECTION = 35
|
170
|
+
XR_TYPE_COMPOSITION_LAYER_QUAD = 36
|
171
|
+
XR_TYPE_REFERENCE_SPACE_CREATE_INFO = 37
|
172
|
+
XR_TYPE_ACTION_SPACE_CREATE_INFO = 38
|
173
|
+
XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING = 40
|
174
|
+
XR_TYPE_VIEW_CONFIGURATION_VIEW = 41
|
175
|
+
XR_TYPE_SPACE_LOCATION = 42
|
176
|
+
XR_TYPE_SPACE_VELOCITY = 43
|
177
|
+
XR_TYPE_FRAME_STATE = 44
|
178
|
+
XR_TYPE_VIEW_CONFIGURATION_PROPERTIES = 45
|
179
|
+
XR_TYPE_FRAME_BEGIN_INFO = 46
|
180
|
+
XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW = 48
|
181
|
+
XR_TYPE_EVENT_DATA_EVENTS_LOST = 49
|
182
|
+
XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING = 51
|
183
|
+
XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED = 52
|
184
|
+
XR_TYPE_INTERACTION_PROFILE_STATE = 53
|
185
|
+
XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO = 55
|
186
|
+
XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO = 56
|
187
|
+
XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO = 57
|
188
|
+
XR_TYPE_ACTION_STATE_GET_INFO = 58
|
189
|
+
XR_TYPE_HAPTIC_ACTION_INFO = 59
|
190
|
+
XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO = 60
|
191
|
+
XR_TYPE_ACTIONS_SYNC_INFO = 61
|
192
|
+
XR_TYPE_BOUND_SOURCES_FOR_ACTION_ENUMERATE_INFO = 62
|
193
|
+
XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO = 63
|
194
|
+
XR_TYPE_COMPOSITION_LAYER_CUBE_KHR = 1000006000
|
195
|
+
XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR = 1000008000
|
196
|
+
XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR = 1000010000
|
197
|
+
XR_TYPE_VULKAN_SWAPCHAIN_FORMAT_LIST_CREATE_INFO_KHR = 1000014000
|
198
|
+
XR_TYPE_EVENT_DATA_PERF_SETTINGS_EXT = 1000015000
|
199
|
+
XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR = 1000017000
|
200
|
+
XR_TYPE_COMPOSITION_LAYER_EQUIRECT_KHR = 1000018000
|
201
|
+
XR_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT = 1000019000
|
202
|
+
XR_TYPE_DEBUG_UTILS_MESSENGER_CALLBACK_DATA_EXT = 1000019001
|
203
|
+
XR_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT = 1000019002
|
204
|
+
XR_TYPE_DEBUG_UTILS_LABEL_EXT = 1000019003
|
205
|
+
XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR = 1000023000
|
206
|
+
XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR = 1000023001
|
207
|
+
XR_TYPE_GRAPHICS_BINDING_OPENGL_XCB_KHR = 1000023002
|
208
|
+
XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR = 1000023003
|
209
|
+
XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR = 1000023004
|
210
|
+
XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR = 1000023005
|
211
|
+
XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR = 1000024001
|
212
|
+
XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR = 1000024002
|
213
|
+
XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_ES_KHR = 1000024003
|
214
|
+
XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR = 1000025000
|
215
|
+
XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR = 1000025001
|
216
|
+
XR_TYPE_GRAPHICS_REQUIREMENTS_VULKAN_KHR = 1000025002
|
217
|
+
XR_TYPE_GRAPHICS_BINDING_D3D11_KHR = 1000027000
|
218
|
+
XR_TYPE_SWAPCHAIN_IMAGE_D3D11_KHR = 1000027001
|
219
|
+
XR_TYPE_GRAPHICS_REQUIREMENTS_D3D11_KHR = 1000027002
|
220
|
+
XR_TYPE_GRAPHICS_BINDING_D3D12_KHR = 1000028000
|
221
|
+
XR_TYPE_SWAPCHAIN_IMAGE_D3D12_KHR = 1000028001
|
222
|
+
XR_TYPE_GRAPHICS_REQUIREMENTS_D3D12_KHR = 1000028002
|
223
|
+
XR_TYPE_SYSTEM_EYE_GAZE_INTERACTION_PROPERTIES_EXT = 1000030000
|
224
|
+
XR_TYPE_EYE_GAZE_SAMPLE_TIME_EXT = 1000030001
|
225
|
+
XR_TYPE_VISIBILITY_MASK_KHR = 1000031000
|
226
|
+
XR_TYPE_EVENT_DATA_VISIBILITY_MASK_CHANGED_KHR = 1000031001
|
227
|
+
XR_TYPE_SESSION_CREATE_INFO_OVERLAY_EXTX = 1000033000
|
228
|
+
XR_TYPE_EVENT_DATA_MAIN_SESSION_VISIBILITY_CHANGED_EXTX = 1000033003
|
229
|
+
XR_TYPE_SPATIAL_ANCHOR_CREATE_INFO_MSFT = 1000039000
|
230
|
+
XR_TYPE_SPATIAL_ANCHOR_SPACE_CREATE_INFO_MSFT = 1000039001
|
231
|
+
XR_TYPE_VIEW_CONFIGURATION_DEPTH_RANGE_EXT = 1000046000
|
232
|
+
XR_TYPE_VIEW_CONFIGURATION_VIEW_FOV_EPIC = 1000059000
|
233
|
+
XR_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
|
82
234
|
|
83
235
|
XrFormFactor = :int # enum
|
84
236
|
XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY = 1
|
@@ -94,6 +246,8 @@ module OpenXR::ABI
|
|
94
246
|
end
|
95
247
|
|
96
248
|
class XrApiLayerProperties < FFI::Struct
|
249
|
+
TYPE = XR_TYPE_API_LAYER_PROPERTIES
|
250
|
+
include InitializeWithType
|
97
251
|
layout :base, XrBaseStructure,
|
98
252
|
:layerName, [:char, XR_MAX_API_LAYER_NAME_SIZE],
|
99
253
|
:specVersion, XrVersion,
|
@@ -102,6 +256,8 @@ module OpenXR::ABI
|
|
102
256
|
end
|
103
257
|
|
104
258
|
class XrExtensionProperties < FFI::Struct
|
259
|
+
TYPE = XR_TYPE_EXTENSION_PROPERTIES
|
260
|
+
include InitializeWithType
|
105
261
|
layout :base, XrBaseStructure,
|
106
262
|
:extensionName, [:char, XR_MAX_EXTENSION_NAME_SIZE],
|
107
263
|
:extensionVersion, :uint32
|
@@ -116,6 +272,8 @@ module OpenXR::ABI
|
|
116
272
|
end
|
117
273
|
|
118
274
|
class XrInstanceCreateInfo < FFI::Struct
|
275
|
+
TYPE = XR_TYPE_INSTANCE_CREATE_INFO
|
276
|
+
include InitializeWithType
|
119
277
|
layout :base, XrBaseStructure,
|
120
278
|
:createFlags, XrInstanceCreateFlags,
|
121
279
|
:applicationInfo, XrApplicationInfo,
|
@@ -126,17 +284,23 @@ module OpenXR::ABI
|
|
126
284
|
end
|
127
285
|
|
128
286
|
class XrInstanceProperties < FFI::Struct
|
287
|
+
TYPE = XR_TYPE_INSTANCE_PROPERTIES
|
288
|
+
include InitializeWithType
|
129
289
|
layout :base, XrBaseStructure,
|
130
290
|
:runtimeVersion, XrVersion,
|
131
291
|
:runtimeName, [:char, XR_MAX_RUNTIME_NAME_SIZE]
|
132
292
|
end
|
133
293
|
|
134
294
|
class XrEventDataBuffer < FFI::Struct
|
295
|
+
TYPE = XR_TYPE_EVENT_DATA_BUFFER
|
296
|
+
include InitializeWithType
|
135
297
|
layout :base, XrBaseStructure,
|
136
298
|
:varying, :uint8
|
137
299
|
end
|
138
300
|
|
139
301
|
class XrSystemGetInfo < FFI::Struct
|
302
|
+
TYPE = XR_TYPE_SYSTEM_GET_INFO
|
303
|
+
include InitializeWithType
|
140
304
|
layout :base, XrBaseStructure,
|
141
305
|
:formFactor, XrFormFactor
|
142
306
|
end
|
@@ -153,6 +317,8 @@ module OpenXR::ABI
|
|
153
317
|
end
|
154
318
|
|
155
319
|
class XrSystemProperties < FFI::Struct
|
320
|
+
TYPE = XR_TYPE_SYSTEM_PROPERTIES
|
321
|
+
include InitializeWithType
|
156
322
|
layout :base, XrBaseStructure,
|
157
323
|
:systemId, XrSystemId,
|
158
324
|
:vendorId, :uint32,
|
@@ -162,6 +328,8 @@ module OpenXR::ABI
|
|
162
328
|
end
|
163
329
|
|
164
330
|
class XrSessionCreateInfo < FFI::Struct
|
331
|
+
TYPE = XR_TYPE_SESSION_CREATE_INFO
|
332
|
+
include InitializeWithType
|
165
333
|
layout :base, XrBaseStructure,
|
166
334
|
:createFlags, XrSessionCreateFlags,
|
167
335
|
:systemId, XrSystemId
|
data/lib/openxr/extension.rb
CHANGED
@@ -15,13 +15,14 @@ class OpenXR::Extension < Struct.new(:name, :version)
|
|
15
15
|
|
16
16
|
##
|
17
17
|
# @return [Integer]
|
18
|
+
# @raise [Result::Error] if `:xrEnumerateInstanceExtensionProperties` failed
|
18
19
|
def self.count
|
19
20
|
response = FFI::MemoryPointer.new(:uint32)
|
20
21
|
begin
|
21
22
|
# https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/openxr.html#_xrenumerateinstanceextensionproperties3
|
22
23
|
case result = xrEnumerateInstanceExtensionProperties(nil, 0, response, nil)
|
23
24
|
when XR_SUCCESS then response.read(:uint32)
|
24
|
-
else raise OpenXR::Result.new(
|
25
|
+
else raise OpenXR::Result.for(result).new(:xrEnumerateInstanceExtensionProperties)
|
25
26
|
end
|
26
27
|
ensure
|
27
28
|
response&.free
|
@@ -44,13 +45,14 @@ class OpenXR::Extension < Struct.new(:name, :version)
|
|
44
45
|
|
45
46
|
##
|
46
47
|
# @return [Hash<Symbol, Extension>]
|
48
|
+
# @raise [Result::Error] if `:xrEnumerateInstanceExtensionProperties` failed
|
47
49
|
def self.query
|
48
50
|
request_count = self.count
|
49
51
|
response_count = FFI::MemoryPointer.new(:uint32)
|
50
52
|
response_array = FFI::MemoryPointer.new(XrExtensionProperties, request_count)
|
51
53
|
begin
|
52
54
|
request_count.times do |i|
|
53
|
-
XrExtensionProperties.new(response_array[i])
|
55
|
+
XrExtensionProperties.new(response_array[i]).set_type!
|
54
56
|
end
|
55
57
|
|
56
58
|
# https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/openxr.html#_xrenumerateinstanceextensionproperties3
|
@@ -63,7 +65,7 @@ class OpenXR::Extension < Struct.new(:name, :version)
|
|
63
65
|
available[extension_name] = self.new(extension_name, extension_version)
|
64
66
|
available
|
65
67
|
end
|
66
|
-
else raise OpenXR::Result.new(
|
68
|
+
else raise OpenXR::Result.for(result).new(:xrEnumerateInstanceExtensionProperties)
|
67
69
|
end
|
68
70
|
ensure
|
69
71
|
response_array&.free
|
data/lib/openxr/instance.rb
CHANGED
@@ -30,6 +30,7 @@ class OpenXR::Instance < OpenXR::Handle
|
|
30
30
|
# @param [String, #to_s] app_name
|
31
31
|
# @param [Integer, #to_i] app_version
|
32
32
|
# @param [Integer, #to_i] api_version
|
33
|
+
# @raise [Result::Error] if `xrCreateInstance` failed
|
33
34
|
def initialize(app_name, app_version: nil, api_version: nil)
|
34
35
|
@struct = XrInstance.new
|
35
36
|
|
@@ -46,7 +47,7 @@ class OpenXR::Instance < OpenXR::Handle
|
|
46
47
|
# https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/openxr.html#_xrcreateinstance3
|
47
48
|
case result = xrCreateInstance(request, @struct)
|
48
49
|
when XR_SUCCESS
|
49
|
-
else raise OpenXR::Result.new(
|
50
|
+
else raise OpenXR::Result.for(result).new(:xrCreateInstance)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
@@ -58,13 +59,13 @@ class OpenXR::Instance < OpenXR::Handle
|
|
58
59
|
|
59
60
|
##
|
60
61
|
# @return [void]
|
62
|
+
# @raise [Result::Error] if `xrDestroyInstance` failed
|
61
63
|
def destroy!
|
62
64
|
return if @struct.nil?
|
63
65
|
# https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/openxr.html#_xrdestroyinstance3
|
64
66
|
case result = xrDestroyInstance(@struct[:handle])
|
65
67
|
when XR_SUCCESS then @struct = nil
|
66
|
-
|
67
|
-
else raise OpenXR::Result.new(result, :xrDestroyInstance) # unreachable
|
68
|
+
else raise OpenXR::Result.for(result).new(:xrDestroyInstance) # unreachable
|
68
69
|
end
|
69
70
|
end
|
70
71
|
end # OpenXR::Instance
|
data/lib/openxr/result.rb
CHANGED
@@ -9,15 +9,49 @@ require_relative 'api'
|
|
9
9
|
class OpenXR::Result < StandardError
|
10
10
|
include OpenXR::API
|
11
11
|
|
12
|
+
# @return [Integer]
|
12
13
|
attr_reader :result
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
# @return [Symbol]
|
16
|
+
attr_reader :function
|
17
|
+
|
18
|
+
##
|
19
|
+
# @param [Integer] result
|
20
|
+
# @return [Class]
|
21
|
+
def self.for(result)
|
22
|
+
case result
|
23
|
+
# https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-successcodes
|
24
|
+
when XR_SUCCESS then Success
|
25
|
+
when XR_TIMEOUT_EXPIRED then Success
|
26
|
+
when XR_SESSION_LOSS_PENDING then Success
|
27
|
+
when XR_EVENT_UNAVAILABLE then Success
|
28
|
+
when XR_SPACE_BOUNDS_UNAVAILABLE then Success
|
29
|
+
when XR_SESSION_NOT_FOCUSED then Success
|
30
|
+
when XR_FRAME_DISCARDED then Success
|
31
|
+
# https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#fundamentals-errorcodes
|
32
|
+
when XR_ERROR_HANDLE_INVALID then HandleInvalid
|
33
|
+
#when XR_ERROR_FORM_FACTOR_UNAVAILABLE then # TODO
|
34
|
+
else self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# @param [Integer, #to_i] result
|
40
|
+
# @param [Symbol] function
|
41
|
+
def initialize(result, function = nil)
|
42
|
+
@result = result.to_i
|
43
|
+
@function = function
|
44
|
+
super(@function ? "#{@function} returned #{@result}" : @result.to_s)
|
17
45
|
end
|
18
46
|
|
19
|
-
class
|
20
|
-
|
47
|
+
class Success < OpenXR::Result; end
|
48
|
+
|
49
|
+
class Error < OpenXR::Result; end
|
50
|
+
|
51
|
+
class HandleInvalid < Error
|
52
|
+
##
|
53
|
+
# @param [Symbol] function
|
54
|
+
def initialize(function = nil)
|
21
55
|
super(XR_ERROR_HANDLE_INVALID, function)
|
22
56
|
end
|
23
57
|
end
|
data/lib/openxr/session.rb
CHANGED
@@ -2,11 +2,59 @@
|
|
2
2
|
|
3
3
|
require_relative 'api'
|
4
4
|
require_relative 'handle'
|
5
|
+
require_relative 'result'
|
5
6
|
|
6
7
|
##
|
7
8
|
# An OpenXR session handle.
|
8
9
|
#
|
9
10
|
# @see https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#session
|
10
11
|
class OpenXR::Session < OpenXR::Handle
|
11
|
-
|
12
|
+
extend OpenXR::API
|
13
|
+
include OpenXR::API
|
14
|
+
|
15
|
+
# @return [Instance]
|
16
|
+
attr_reader :instance
|
17
|
+
|
18
|
+
# @return [System]
|
19
|
+
attr_reader :system
|
20
|
+
|
21
|
+
##
|
22
|
+
# @param [System]
|
23
|
+
# @param [XrGraphicsBinding] graphics_binding
|
24
|
+
# @raise [Result::Error] if `xrCreateSession` failed
|
25
|
+
def initialize(system, graphics_binding = nil)
|
26
|
+
@instance = system.instance
|
27
|
+
@system = system
|
28
|
+
@struct = XrSession.new
|
29
|
+
|
30
|
+
# https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/openxr.html#_xrsessioncreateinfo3
|
31
|
+
request = XrSessionCreateInfo.new
|
32
|
+
request[:base][:next] = graphics_binding
|
33
|
+
request[:createFlags] = 0
|
34
|
+
request[:systemId] = system.id
|
35
|
+
|
36
|
+
# https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/openxr.html#_xrcreatesession3
|
37
|
+
case result = xrCreateSession(instance.handle, request, @struct)
|
38
|
+
when XR_SUCCESS
|
39
|
+
else raise OpenXR::Result.for(result).new(:xrCreateSession)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# @return [FFI::Pointer]
|
45
|
+
def handle
|
46
|
+
@struct[:handle]
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# @return [void]
|
51
|
+
# @raise [Result::Error] if `xrDestroySession` failed
|
52
|
+
def destroy!
|
53
|
+
return if @struct.nil?
|
54
|
+
# https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/openxr.html#_xrdestroysession3
|
55
|
+
case result = xrDestroySession(@struct[:handle])
|
56
|
+
when XR_SUCCESS then @struct = nil
|
57
|
+
else raise OpenXR::Result.for(result).new(:xrDestroySession) # unreachable
|
58
|
+
end
|
59
|
+
end
|
12
60
|
end # OpenXR::Session
|
data/lib/openxr/system.rb
CHANGED
@@ -14,11 +14,11 @@ class OpenXR::System
|
|
14
14
|
##
|
15
15
|
# @param [Instance] instance
|
16
16
|
# @param [XrFormFactor, #to_i] form_factor
|
17
|
-
# @return [System]
|
17
|
+
# @return [System] if the form factor is supported
|
18
|
+
# @raise [Result::Error] if `xrGetSystem` failed
|
18
19
|
# @see https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#form_factor_description
|
19
20
|
def self.for_form_factor(instance, form_factor)
|
20
21
|
request = XrSystemGetInfo.new
|
21
|
-
request[:base][:type] = XR_TYPE_SYSTEM_GET_INFO
|
22
22
|
request[:formFactor] = form_factor.to_i
|
23
23
|
system_id = FFI::MemoryPointer.new(XrSystemId)
|
24
24
|
|
@@ -26,8 +26,8 @@ class OpenXR::System
|
|
26
26
|
# https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/openxr.html#_xrgetsystem3
|
27
27
|
case result = xrGetSystem(instance.handle, request, system_id)
|
28
28
|
when XR_SUCCESS then self.new(instance, system_id.read(XrSystemId))
|
29
|
-
|
30
|
-
else raise OpenXR::Result.new(
|
29
|
+
when XR_ERROR_FORM_FACTOR_UNAVAILABLE then nil
|
30
|
+
else raise OpenXR::Result.for(result).new(:xrGetSystem)
|
31
31
|
end
|
32
32
|
ensure
|
33
33
|
system_id&.free
|
@@ -55,12 +55,12 @@ class OpenXR::System
|
|
55
55
|
##
|
56
56
|
# @param [Instance] instance
|
57
57
|
# @param [API::XrSystemId, #to_i] id
|
58
|
+
# @raise [Result::Error] if `xrGetSystemProperties` failed
|
58
59
|
def initialize(instance, id)
|
59
60
|
@instance = instance
|
60
61
|
@id = id.to_i
|
61
62
|
|
62
63
|
response = XrSystemProperties.new
|
63
|
-
response[:base][:type] = XR_TYPE_SYSTEM_PROPERTIES
|
64
64
|
|
65
65
|
# https://www.khronos.org/registry/OpenXR/specs/1.0/man/html/openxr.html#_xrgetsystemproperties3
|
66
66
|
case result = xrGetSystemProperties(@instance.handle, @id, response)
|
@@ -76,7 +76,7 @@ class OpenXR::System
|
|
76
76
|
:orientation_tracking => response[:trackingProperties][:orientationTracking] == XR_TRUE,
|
77
77
|
:position_tracking => response[:trackingProperties][:positionTracking] == XR_TRUE,
|
78
78
|
}
|
79
|
-
else raise OpenXR::Result.new(
|
79
|
+
else raise OpenXR::Result.for(result).new(:xrGetSystemProperties)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end # OpenXR::System
|