|
| 1 | +/* |
| 2 | + * Copyright 2024-2025 Diligent Graphics LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * In no event and under no legal theory, whether in tort (including negligence), |
| 17 | + * contract, or otherwise, unless required by applicable law (such as deliberate |
| 18 | + * and grossly negligent acts) or agreed to in writing, shall any Contributor be |
| 19 | + * liable for any damages, including any direct, indirect, special, incidental, |
| 20 | + * or consequential damages of any character arising as a result of this License or |
| 21 | + * out of the use or inability to use the software (including but not limited to damages |
| 22 | + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and |
| 23 | + * all other commercial damages or losses), even if such Contributor has been advised |
| 24 | + * of the possibility of such damages. |
| 25 | + */ |
| 26 | + |
| 27 | +#pragma once |
| 28 | + |
| 29 | +/// \file |
| 30 | +/// CompositorServices utilities for visionOS |
| 31 | + |
| 32 | +#include "../../GraphicsEngine/interface/RenderDevice.h" |
| 33 | +#include "../../GraphicsEngine/interface/DeviceContext.h" |
| 34 | +#include "../../../Primitives/interface/BasicTypes.h" |
| 35 | +#include "../../../Common/interface/BasicMath.hpp" |
| 36 | + |
| 37 | +#include <CompositorServices/CompositorServices.h> |
| 38 | + |
| 39 | +DILIGENT_BEGIN_NAMESPACE(Diligent) |
| 40 | + |
| 41 | +#include "../../../Primitives/interface/DefineRefMacro.h" |
| 42 | + |
| 43 | +/// Type of texture to retrieve from a CompositorServices drawable. |
| 44 | +DILIGENT_TYPED_ENUM(COMPOSITOR_SERVICES_TEXTURE_TYPE, Uint8) |
| 45 | +{ |
| 46 | + /// Color texture (render target). |
| 47 | + COMPOSITOR_SERVICES_TEXTURE_TYPE_COLOR = 0, |
| 48 | + |
| 49 | + /// Depth texture. |
| 50 | + COMPOSITOR_SERVICES_TEXTURE_TYPE_DEPTH |
| 51 | +}; |
| 52 | + |
| 53 | +/// Returns the number of views (eyes) in a CompositorServices drawable. |
| 54 | +/// |
| 55 | +/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t). |
| 56 | +/// \return Number of views (typically 2 for stereo rendering). |
| 57 | +Uint32 DILIGENT_GLOBAL_FUNCTION(GetCompositorServicesViewCount)(cp_drawable_t Drawable); |
| 58 | + |
| 59 | +/// Returns a Diligent ITexture wrapping the Metal texture from a CompositorServices drawable. |
| 60 | +/// |
| 61 | +/// \param [in] pDevice - Pointer to the render device. |
| 62 | +/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t). |
| 63 | +/// \param [in] ViewIndex - Index of the view (eye) to get the texture for. |
| 64 | +/// \param [in] TexType - Type of texture to retrieve (color or depth). |
| 65 | +/// \param [out] ppTexture - Address of the memory location where the pointer to the |
| 66 | +/// texture object will be stored. |
| 67 | +void DILIGENT_GLOBAL_FUNCTION(GetCompositorServicesSwapchainImage)(IRenderDevice* pDevice, |
| 68 | + cp_drawable_t Drawable, |
| 69 | + Uint32 ViewIndex, |
| 70 | + COMPOSITOR_SERVICES_TEXTURE_TYPE TexType, |
| 71 | + ITexture** ppTexture); |
| 72 | + |
| 73 | +/// Returns the projection matrix for a specific view in a CompositorServices drawable. |
| 74 | +/// |
| 75 | +/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t). |
| 76 | +/// \param [in] ViewIndex - Index of the view (eye). |
| 77 | +/// \param [in] NearZ - Near clipping plane distance. |
| 78 | +/// \param [in] FarZ - Far clipping plane distance. |
| 79 | +/// \return The 4x4 projection matrix for the specified view. |
| 80 | +float4x4 DILIGENT_GLOBAL_FUNCTION(GetCompositorServicesProjectionMatrix)(cp_drawable_t Drawable, |
| 81 | + Uint32 ViewIndex, |
| 82 | + float NearZ, |
| 83 | + float FarZ); |
| 84 | + |
| 85 | +/// Returns the view transform matrix for a specific view in a CompositorServices drawable. |
| 86 | +/// |
| 87 | +/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t). |
| 88 | +/// \param [in] ViewIndex - Index of the view (eye). |
| 89 | +/// \return The 4x4 view transform matrix for the specified view. |
| 90 | +float4x4 DILIGENT_GLOBAL_FUNCTION(GetCompositorServicesViewTransform)(cp_drawable_t Drawable, |
| 91 | + Uint32 ViewIndex); |
| 92 | + |
| 93 | +/// Presents the CompositorServices drawable by encoding a present command into the |
| 94 | +/// Metal command buffer obtained from the device context. |
| 95 | +/// |
| 96 | +/// \param [in] pContext - Pointer to the device context. |
| 97 | +/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t) to present. |
| 98 | +/// |
| 99 | +/// This function hides all ObjC++/Metal details from the caller, |
| 100 | +/// allowing tutorials to be pure C++. |
| 101 | +void DILIGENT_GLOBAL_FUNCTION(PresentCompositorServicesDrawable)(IDeviceContext* pContext, |
| 102 | + cp_drawable_t Drawable); |
| 103 | + |
| 104 | +#include "../../../Primitives/interface/UndefRefMacro.h" |
| 105 | + |
| 106 | +DILIGENT_END_NAMESPACE // namespace Diligent |
0 commit comments