Updated Mac and iOS native window structs
assiduous
3 years ago
41 | 41 | const SwapChainDesc& SCDesc, |
42 | 42 | class RenderDeviceMtlImpl* pRenderDeviceMtl, |
43 | 43 | class DeviceContextMtlImpl* pDeviceContextMtl, |
44 | void* pView); | |
44 | const NativeWindow& Window); | |
45 | 45 | ~SwapChainMtlImpl(); |
46 | 46 | |
47 | 47 | virtual void QueryInterface(const Diligent::INTERFACE_ID& IID, IObject** ppInterface) override final; |
52 | 52 | virtual void CreateSwapChainMtl(IRenderDevice* pDevice, |
53 | 53 | IDeviceContext* pImmediateContext, |
54 | 54 | const SwapChainDesc& SCDesc, |
55 | void* pView, | |
55 | const NativeWindow& Window, | |
56 | 56 | ISwapChain** ppSwapChain) = 0; |
57 | 57 | |
58 | 58 | virtual void AttachToMtlDevice(void* pMtlNativeDevice, |
53 | 53 | IRenderDevice** ppDevice, |
54 | 54 | IDeviceContext** ppContexts)override final; |
55 | 55 | |
56 | void CreateSwapChainMtl( IRenderDevice* pDevice, | |
57 | IDeviceContext* pImmediateContext, | |
58 | const SwapChainDesc& SCDesc, | |
59 | void* pView, | |
60 | ISwapChain** ppSwapChain )override final; | |
56 | void CreateSwapChainMtl( IRenderDevice* pDevice, | |
57 | IDeviceContext* pImmediateContext, | |
58 | const SwapChainDesc& SCDesc, | |
59 | const NativeWindow& Window, | |
60 | ISwapChain** ppSwapChain )override final; | |
61 | 61 | |
62 | 62 | void AttachToMtlDevice(void* pMtlNativeDevice, |
63 | 63 | const EngineMtlCreateInfo& EngineCI, |
178 | 178 | /// |
179 | 179 | /// \param [out] ppSwapChain - Address of the memory location where pointer to the new |
180 | 180 | /// swap chain will be written |
181 | void EngineFactoryMtlImpl::CreateSwapChainMtl(IRenderDevice* pDevice, | |
182 | IDeviceContext* pImmediateContext, | |
183 | const SwapChainDesc& SCDesc, | |
184 | void* pView, | |
185 | ISwapChain** ppSwapChain ) | |
181 | void EngineFactoryMtlImpl::CreateSwapChainMtl(IRenderDevice* pDevice, | |
182 | IDeviceContext* pImmediateContext, | |
183 | const SwapChainDesc& SCDesc, | |
184 | const NativeWindow& Window, | |
185 | ISwapChain** ppSwapChain ) | |
186 | 186 | { |
187 | 187 | VERIFY( ppSwapChain, "Null pointer provided" ); |
188 | 188 | if( !ppSwapChain ) |
197 | 197 | auto &RawMemAllocator = GetRawAllocator(); |
198 | 198 | |
199 | 199 | auto *pSwapChainMtl = NEW_RC_OBJ(RawMemAllocator, "SwapChainMtlImpl instance", SwapChainMtlImpl) |
200 | (SCDesc, pDeviceMtl, pDeviceContextMtl, pView); | |
200 | (SCDesc, pDeviceMtl, pDeviceContextMtl, Window); | |
201 | 201 | pSwapChainMtl->QueryInterface( IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain) ); |
202 | 202 | } |
203 | 203 | catch( const std::runtime_error & ) |
31 | 31 | const SwapChainDesc& SCDesc, |
32 | 32 | RenderDeviceMtlImpl* pRenderDeviceMtl, |
33 | 33 | DeviceContextMtlImpl* pDeviceContextMtl, |
34 | void* pNativeWndHandle) : | |
34 | const NativeWindow& Window) : | |
35 | 35 | TSwapChainBase(pRefCounters, pRenderDeviceMtl, pDeviceContextMtl, SCDesc) |
36 | 36 | { |
37 | 37 | LOG_ERROR_AND_THROW("Swap chain is not implemented in Metal backend"); |
45 | 45 | //Or better yet, use the GL3 way to get the version number |
46 | 46 | glGetIntegerv( GL_MAJOR_VERSION, &MajorVersion ); |
47 | 47 | glGetIntegerv( GL_MINOR_VERSION, &MinorVersion ); |
48 | LOG_INFO_MESSAGE(Info.Window.pNSView != nullptr ? "Initialized OpenGLES " : "Attached to OpenGLES ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ", ", GLRenderer, ')'); | |
48 | LOG_INFO_MESSAGE(Info.Window.pCALayer != nullptr ? "Initialized OpenGLES " : "Attached to OpenGLES ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ", ", GLRenderer, ')'); | |
49 | 49 | |
50 | 50 | // Under the standard filtering rules for cubemaps, filtering does not work across faces of the cubemap. |
51 | 51 | // This results in a seam across the faces of a cubemap. This was a hardware limitation in the past, but |
73 | 73 | //Or better yet, use the GL3 way to get the version number |
74 | 74 | glGetIntegerv( GL_MAJOR_VERSION, &MajorVersion ); |
75 | 75 | glGetIntegerv( GL_MINOR_VERSION, &MinorVersion ); |
76 | LOG_INFO_MESSAGE(InitAttribs.Window.pNSWindow != nullptr ? "Initialized OpenGL " : "Attached to OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ", ", GLRenderer, ')'); | |
76 | LOG_INFO_MESSAGE(InitAttribs.Window.pNSView != nullptr ? "Initialized OpenGL " : "Attached to OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ", ", GLRenderer, ')'); | |
77 | 77 | |
78 | 78 | // Under the standard filtering rules for cubemaps, filtering does not work across faces of the cubemap. |
79 | 79 | // This results in a seam across the faces of a cubemap. This was a hardware limitation in the past, but |
42 | 42 | m_DepthRenderBuffer(false), |
43 | 43 | m_DefaultFBO(false) |
44 | 44 | { |
45 | m_CALayer = InitAttribs.Window.pNSView; | |
45 | m_CALayer = InitAttribs.Window.pCALayer; | |
46 | 46 | InitRenderBuffers(true, m_SwapChainDesc.Width, m_SwapChainDesc.Height); |
47 | 47 | CreateDummyBuffers(m_pRenderDevice.RawPtr<RenderDeviceGLImpl>()); |
48 | 48 | } |
68 | 68 | VkIOSSurfaceCreateInfoMVK surfaceCreateInfo = {}; |
69 | 69 | |
70 | 70 | surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK; |
71 | surfaceCreateInfo.pView = Window.pNSView; | |
71 | surfaceCreateInfo.pView = Window.pCALayer; | |
72 | 72 | |
73 | 73 | auto err = vkCreateIOSSurfaceMVK(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, nullptr, &m_VkSurface); |
74 | 74 | #elif defined(VK_USE_PLATFORM_MACOS_MVK) |
75 | 75 | VkMacOSSurfaceCreateInfoMVK surfaceCreateInfo = {}; |
76 | 76 | |
77 | 77 | surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; |
78 | surfaceCreateInfo.pView = Window.pNSWindow; | |
78 | surfaceCreateInfo.pView = Window.pNSView; | |
79 | 79 | |
80 | 80 | auto err = vkCreateMacOSSurfaceMVK(m_VulkanInstance->GetVkInstance(), &surfaceCreateInfo, NULL, &m_VkSurface); |
81 | 81 | #elif defined(VK_USE_PLATFORM_WAYLAND_KHR) |
32 | 32 | |
33 | 33 | struct IOSNativeWindow |
34 | 34 | { |
35 | void* pNSView DEFAULT_INITIALIZER(nullptr); | |
35 | void* pCALayer DEFAULT_INITIALIZER(nullptr); | |
36 | ||
37 | #if DILIGENT_CPP_INTERFACE | |
38 | IOSNativeWindow() noexcept | |
39 | {} | |
40 | ||
41 | explicit IOSNativeWindow(void* _pCALayer) noexcept : | |
42 | pCALayer{_pCALayer} | |
43 | {} | |
44 | #endif | |
36 | 45 | }; |
37 | 46 | |
38 | 47 | DILIGENT_END_NAMESPACE // namespace Diligent |
32 | 32 | |
33 | 33 | struct MacOSNativeWindow |
34 | 34 | { |
35 | void* pNSWindow DEFAULT_INITIALIZER(nullptr); | |
35 | void* pNSView DEFAULT_INITIALIZER(nullptr); | |
36 | ||
37 | #if DILIGENT_CPP_INTERFACE | |
38 | MacOSNativeWindow() noexcept | |
39 | {} | |
40 | ||
41 | explicit MacOSNativeWindow(void* _pNSView) noexcept : | |
42 | pNSView(_pNSView) | |
43 | {} | |
44 | #endif | |
36 | 45 | }; |
37 | 46 | |
38 | 47 | DILIGENT_END_NAMESPACE // namespace Diligent |