···1212#pragma once
13131414#include "xrt/xrt_defines.h"
1515+#include "xrt/xrt_plane_detector.h"
1516#include "xrt/xrt_visibility_mask.h"
1617#include "xrt/xrt_limits.h"
1718···284285 bool face_tracking_supported;
285286 bool body_tracking_supported;
286287 bool battery_status_supported;
288288+ bool planes_supported;
289289+ enum xrt_plane_detection_capability_flags_ext plane_capability_flags;
287290288291 /*
289292 *
···415418 void (*set_output)(struct xrt_device *xdev, enum xrt_output_name name, const union xrt_output_value *value);
416419417420 /*!
421421+ * Begin a plane detection request
422422+ *
423423+ * @param[in] xdev The device.
424424+ * @param[in] begin_info The query specifying what type of planes are requested.
425425+ * @param[in] plane_detection_id The id for a previous plane detection request to be replaced or 0.
426426+ * @param[out] out_plane_detection_id The id of the new plane detection request generated by the xdev.
427427+ * @return generally XRT_SUCCESS, except for internal runtime failures.
428428+ */
429429+ enum xrt_result (*begin_plane_detection_ext)(struct xrt_device *xdev,
430430+ const struct xrt_plane_detector_begin_info_ext *begin_info,
431431+ uint64_t plane_detection_id,
432432+ uint64_t *out_plane_detection_id);
433433+434434+ /*!
435435+ * Destroy internal resources associated with plane_detector_id.
436436+ *
437437+ * @param[in] xdev The device.
438438+ * @param[in] plane_detection_id An id generated by the xdev.
439439+ * @return generally XRT_SUCCESS, except for internal runtime failures.
440440+ */
441441+ enum xrt_result (*destroy_plane_detection_ext)(struct xrt_device *xdev, uint64_t plane_detection_id);
442442+443443+ /*!
444444+ * Get the state of a plane detection request.
445445+ *
446446+ * @param[in] xdev The device.
447447+ * @param[in] plane_detector_id An id generated by the xdev.
448448+ * @param[out] out_state The state of the plane detection.
449449+ * @return generally XRT_SUCCESS, except for internal runtime failures.
450450+ */
451451+ enum xrt_result (*get_plane_detection_state_ext)(struct xrt_device *xdev,
452452+ uint64_t plane_detection_id,
453453+ enum xrt_plane_detector_state_ext *out_state);
454454+455455+ /*!
456456+ * Get results of a plane detection request.
457457+ *
458458+ * @param[in] xdev The device.
459459+ * @param[in] plane_detector_id An id generated by the xdev.
460460+ * @param[out] detections The detected planes, if any.
461461+ * @return generally XRT_SUCCESS, except for internal runtime failures.
462462+ */
463463+ enum xrt_result (*get_plane_detections_ext)(struct xrt_device *xdev,
464464+ uint64_t plane_detection_id,
465465+ struct xrt_plane_detections_ext *out_detections);
466466+467467+ /*!
418468 * @brief Get the per-view pose in relation to the view space.
419469 *
420470 * On most devices with coplanar displays and no built-in eye tracking
···661711xrt_device_set_output(struct xrt_device *xdev, enum xrt_output_name name, const union xrt_output_value *value)
662712{
663713 xdev->set_output(xdev, name, value);
714714+}
715715+716716+/*!
717717+ * Helper function for @ref xrt_device::begin_plane_detection.
718718+ *
719719+ * @public @memberof xrt_device
720720+ */
721721+static inline enum xrt_result
722722+xrt_device_begin_plane_detection_ext(struct xrt_device *xdev,
723723+ const struct xrt_plane_detector_begin_info_ext *begin_info,
724724+ uint64_t plane_detection_id,
725725+ uint64_t *out_plane_detection_id)
726726+{
727727+ return xdev->begin_plane_detection_ext(xdev, begin_info, plane_detection_id, out_plane_detection_id);
728728+}
729729+730730+/*!
731731+ * Helper function for @ref xrt_device::destroy_plane_detection.
732732+ *
733733+ * @public @memberof xrt_device
734734+ */
735735+static inline enum xrt_result
736736+xrt_device_destroy_plane_detection_ext(struct xrt_device *xdev, uint64_t plane_detection_id)
737737+{
738738+ return xdev->destroy_plane_detection_ext(xdev, plane_detection_id);
739739+}
740740+741741+/*!
742742+ * Helper function for @ref xrt_device::get_plane_detections.
743743+ *
744744+ * @public @memberof xrt_device
745745+ */
746746+static inline enum xrt_result
747747+xrt_device_get_plane_detection_state_ext(struct xrt_device *xdev,
748748+ uint64_t plane_detection_id,
749749+ enum xrt_plane_detector_state_ext *out_state)
750750+{
751751+ return xdev->get_plane_detection_state_ext(xdev, plane_detection_id, out_state);
752752+}
753753+754754+/*!
755755+ * Helper function for @ref xrt_device::get_plane_detections.
756756+ *
757757+ * @public @memberof xrt_device
758758+ */
759759+static inline enum xrt_result
760760+xrt_device_get_plane_detections_ext(struct xrt_device *xdev,
761761+ uint64_t plane_detection_id,
762762+ struct xrt_plane_detections_ext *out_detections)
763763+{
764764+ return xdev->get_plane_detections_ext(xdev, plane_detection_id, out_detections);
664765}
665766666767/*!
+10
src/xrt/include/xrt/xrt_limits.h
···3939#define XRT_MAX_SWAPCHAIN_FORMATS 16
40404141/*!
4242+ * Max number of plane orientations that can be requested at a time.
4343+ */
4444+#define XRT_MAX_PLANE_ORIENTATIONS_EXT 256
4545+4646+/*!
4747+ * Max number of plane semantic types that can be requested at a time.
4848+ */
4949+#define XRT_MAX_PLANE_SEMANTIC_TYPE_EXT 256
5050+5151+/*!
4252 * Max formats in the swapchain creation info formats list, artificial limit.
4353 */
4454#define XRT_MAX_SWAPCHAIN_CREATE_INFO_FORMAT_LIST_COUNT 8
+217
src/xrt/include/xrt/xrt_plane_detector.h
···11+// Copyright 2023-2025, Collabora, Ltd.
22+// SPDX-License-Identifier: BSL-1.0
33+/*!
44+ * @file
55+ * @brief Header defining planes detector enum and structs.
66+ * @author Christoph Haag <christoph.haag@collabora.com>
77+ * @ingroup xrt_iface
88+ */
99+1010+1111+#pragma once
1212+1313+#include "xrt/xrt_defines.h"
1414+#include "xrt/xrt_limits.h"
1515+1616+#include <stdlib.h>
1717+#include <string.h>
1818+1919+#ifdef __cplusplus
2020+extern "C" {
2121+#endif
2222+2323+2424+/*!
2525+ * Caps for a plane detector, see @ref xrt_device.
2626+ *
2727+ * @ingroup xrt_iface
2828+ */
2929+enum xrt_plane_detection_capability_flags_ext
3030+{
3131+ XRT_PLANE_DETECTION_CAPABILITY_PLANE_DETECTION_BIT_EXT = 0x00000001,
3232+ XRT_PLANE_DETECTION_CAPABILITY_PLANE_HOLES_BIT_EXT = 0x00000002,
3333+ XRT_PLANE_DETECTION_CAPABILITY_SEMANTIC_CEILING_BIT_EXT = 0x00000004,
3434+ XRT_PLANE_DETECTION_CAPABILITY_SEMANTIC_FLOOR_BIT_EXT = 0x00000008,
3535+ XRT_PLANE_DETECTION_CAPABILITY_SEMANTIC_WALL_BIT_EXT = 0x00000010,
3636+ XRT_PLANE_DETECTION_CAPABILITY_SEMANTIC_PLATFORM_BIT_EXT = 0x00000020,
3737+ XRT_PLANE_DETECTION_CAPABILITY_ORIENTATION_BIT_EXT = 0x00000040,
3838+};
3939+4040+/*!
4141+ * Flags used when running plane detection.
4242+ *
4343+ * @ingroup xrt_iface
4444+ */
4545+enum xrt_plane_detector_flags_ext
4646+{
4747+ XRT_PLANE_DETECTOR_FLAGS_CONTOUR_EXT = 1,
4848+};
4949+5050+/*!
5151+ * Orientation of a plane.
5252+ *
5353+ * @ingroup xrt_iface
5454+ */
5555+enum xrt_plane_detector_orientation_ext
5656+{
5757+ XRT_PLANE_DETECTOR_ORIENTATION_HORIZONTAL_UPWARD_EXT = 0,
5858+ XRT_PLANE_DETECTOR_ORIENTATION_HORIZONTAL_DOWNWARD_EXT = 1,
5959+ XRT_PLANE_DETECTOR_ORIENTATION_VERTICAL_EXT = 2,
6060+ XRT_PLANE_DETECTOR_ORIENTATION_ARBITRARY_EXT = 3,
6161+};
6262+6363+/*!
6464+ * Has this plane any semantic meaning?
6565+ *
6666+ * @ingroup xrt_iface
6767+ */
6868+enum xrt_plane_detector_semantic_type_ext
6969+{
7070+ XRT_PLANE_DETECTOR_SEMANTIC_TYPE_UNDEFINED_EXT = 0,
7171+ XRT_PLANE_DETECTOR_SEMANTIC_TYPE_CEILING_EXT = 1,
7272+ XRT_PLANE_DETECTOR_SEMANTIC_TYPE_FLOOR_EXT = 2,
7373+ XRT_PLANE_DETECTOR_SEMANTIC_TYPE_WALL_EXT = 3,
7474+ XRT_PLANE_DETECTOR_SEMANTIC_TYPE_PLATFORM_EXT = 4,
7575+};
7676+7777+/*!
7878+ * State of a plane detector, see @ref xrt_device.
7979+ *
8080+ * @ingroup xrt_iface
8181+ */
8282+enum xrt_plane_detector_state_ext
8383+{
8484+ XRT_PLANE_DETECTOR_STATE_NONE_EXT = 0,
8585+ XRT_PLANE_DETECTOR_STATE_PENDING_EXT = 1,
8686+ XRT_PLANE_DETECTOR_STATE_DONE_EXT = 2,
8787+ XRT_PLANE_DETECTOR_STATE_ERROR_EXT = 3,
8888+ XRT_PLANE_DETECTOR_STATE_FATAL_EXT = 4,
8989+};
9090+9191+/*!
9292+ * A query for a plane. Corresponds to XrPlaneDetectorBeginInfoEXT.
9393+ *
9494+ * @ingroup xrt_iface
9595+ */
9696+struct xrt_plane_detector_begin_info_ext
9797+{
9898+ enum xrt_plane_detector_flags_ext detector_flags;
9999+ uint32_t orientation_count;
100100+ enum xrt_plane_detector_orientation_ext orientations[XRT_MAX_PLANE_ORIENTATIONS_EXT];
101101+ uint32_t semantic_type_count;
102102+ enum xrt_plane_detector_semantic_type_ext semantic_types[XRT_MAX_PLANE_SEMANTIC_TYPE_EXT];
103103+ uint32_t max_planes;
104104+ float min_area;
105105+ struct xrt_pose bounding_box_pose;
106106+ //! width, height, depth
107107+ struct xrt_vec3 bounding_box_extent;
108108+};
109109+110110+/*!
111111+ * Location and other info for a plane.
112112+ *
113113+ * @ingroup xrt_iface
114114+ */
115115+struct xrt_plane_detector_location_ext
116116+{
117117+ uint64_t planeId;
118118+ struct xrt_space_relation relation;
119119+ //! x = width, y = height
120120+ struct xrt_vec2 extents;
121121+ enum xrt_plane_detector_orientation_ext orientation;
122122+ enum xrt_plane_detector_semantic_type_ext semantic_type;
123123+ uint32_t polygon_buffer_count;
124124+};
125125+126126+/*!
127127+ * Helper struct to pair up metadata for one polygon.
128128+ *
129129+ * @ingroup xrt_iface
130130+ */
131131+struct xrt_plane_polygon_info_ext
132132+{
133133+ uint32_t vertex_count;
134134+135135+ //! Index into the continuous array of vertices for all planes of a query.
136136+ uint32_t vertices_start_index;
137137+};
138138+139139+/*!
140140+ * Each plane has n polygons; ultimately plane metadata from @ref locations and @ref vetices is
141141+ * reconstructed. Therefore lay out the data in flattened arrays:
142142+ *
143143+ * @ref locations stores continuous metadata for each plane:
144144+ * location 1 | location 2 | location 3 | location 4 | ...
145145+ *
146146+ * @ref polygon_info_start_index is a helper array to go from a location entry to a polygon_info entry.
147147+ *
148148+ * @ref polygon_info stores info (metadata) for each polygon, flattened:
149149+ * plane 1 polygon 1 info | plane 1 polygon 2 info | ... | plane 2 polygon 1 info | ...
150150+ *
151151+ * @ref polygon_info.vertices_start_index is a helper array to go from a polygon_info entry to vertices
152152+ * entry.
153153+ *
154154+ * @ref vertices stores vertex data for each polygon, for each plane, flattened:
155155+ * plane 1 polygon 1 vertex 1 | plane 1 polygon 1 vertex 2 | ... | plane 1 polygon 2 vertex 1 | ...
156156+ *
157157+ * To reconstruct the vertices of a certain plane polygon:
158158+ * - Find the index i of the plane with the requested plane_id in the locations array.
159159+ * - Use this index i to generate a new index j = polygon_info_start_index[i].
160160+ * - polygon_info[j] is the info of the first polygon of the locations[i] plane.
161161+ * - polygon_info[j + polygonBufferIndex] is the info of the requested polygon.
162162+ * - polygon_info[j + polygonBufferIndex].vertex_count is the vertex count of this polygon.
163163+ * - polygon_info[j + polygonBufferIndex].vertices_start_index is another new index k.
164164+ * - vertices[k] is the first vertex of the requested polygon.
165165+ *
166166+ * Convention: Whoever writes to this struct checks the size values first and reallocates arrays if necessary.
167167+ *
168168+ * @ingroup xrt_iface
169169+ */
170170+struct xrt_plane_detections_ext
171171+{
172172+ //! How many locations were found.
173173+ uint32_t location_count;
174174+175175+ //! size of @ref locations and @ref polygon_info_start_index arrays.
176176+ uint32_t location_size;
177177+178178+ ///! array of detected locations.
179179+ struct xrt_plane_detector_location_ext *locations;
180180+181181+ //! Parallel array to @ref locations.
182182+ //! Index into @ref polygon_info of polygon_infos for all planes of a query.
183183+ uint32_t *polygon_info_start_index;
184184+185185+ //! size of @ref polygon_infos array.
186186+ uint32_t polygon_info_size;
187187+188188+ //! Continuous array of polygon_infos of all polygons for all planes of a query.
189189+ struct xrt_plane_polygon_info_ext *polygon_infos;
190190+191191+ //! size of @ref vertices array.
192192+ uint32_t vertex_size;
193193+194194+ //! Continuous array of polygon vertices of all polygons for all planes of a query.
195195+ struct xrt_vec2 *vertices;
196196+};
197197+198198+/*!
199199+ * Small helper to free any data of a @ref xrt_plane_detections_ext struct,
200200+ * does not free the struct itself.
201201+ *
202202+ * @ingroup xrt_iface
203203+ */
204204+static inline void
205205+xrt_plane_detections_ext_clear(struct xrt_plane_detections_ext *detections)
206206+{
207207+ free(detections->locations);
208208+ free(detections->polygon_info_start_index);
209209+ free(detections->polygon_infos);
210210+ free(detections->vertices);
211211+ memset(detections, 0, sizeof(*detections));
212212+}
213213+214214+215215+#ifdef __cplusplus
216216+}
217217+#endif