Skip to content

Commit

Permalink
[UWP] Added initial support for Universal Windows Platform (UWP).
Browse files Browse the repository at this point in the history
- UWP support requires C++17.
- UWP apps must use LoadPackagedLibrary() instead of LoadLibrary() to load modules.
- Added support for UWP's CoreWindow in D3D11 and D3D12 swap-chains.
- Added HelloUWP example.
  • Loading branch information
LukasBanana committed May 20, 2024
1 parent ff08ccb commit f2879ef
Show file tree
Hide file tree
Showing 28 changed files with 1,173 additions and 58 deletions.
60 changes: 38 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@ else()
set(LLGL_BUILD_64BIT OFF)
endif()

set(LLGL_UWP_PLATFORM OFF)
set(LLGL_IOS_PLATFORM OFF)
set(LLGL_ANDROID_PLATFORM OFF)

if(NOT DEFINED LLGL_TARGET_PLATFORM)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
set(LLGL_TARGET_PLATFORM "Android")
if(NOT DEFINED ENV{ANDROID_NDK_ROOT})
message(FATAL_ERROR "Cannot build for Android platform: Missing environment variable 'ANDROID_NDK_ROOT'")
endif()
set(LLGL_ANDROID_PLATFORM ON)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
set(LLGL_TARGET_PLATFORM "${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
set(LLGL_UWP_PLATFORM ON)
elseif(WIN32)
if(LLGL_BUILD_64BIT)
set(LLGL_TARGET_PLATFORM "Win64")
Expand All @@ -31,6 +42,7 @@ if(NOT DEFINED LLGL_TARGET_PLATFORM)
elseif(APPLE)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
set(LLGL_TARGET_PLATFORM "iOS")
set(LLGL_IOS_PLATFORM ON)
else()
set(LLGL_TARGET_PLATFORM "macOS")
endif()
Expand All @@ -39,22 +51,15 @@ if(NOT DEFINED LLGL_TARGET_PLATFORM)
endif()
endif()

set(LLGL_IOS_PLATFORM OFF)
set(LLGL_ANDROID_PLATFORM OFF)

if(${LLGL_TARGET_PLATFORM} STREQUAL "iOS")
set(LLGL_IOS_PLATFORM ON)
elseif(${LLGL_TARGET_PLATFORM} STREQUAL "Android")
if(NOT DEFINED ENV{ANDROID_NDK_ROOT})
message(FATAL_ERROR "Cannot build for Android platform: Missing environment variable 'ANDROID_NDK_ROOT'")
endif()
set(LLGL_ANDROID_PLATFORM ON)
endif()


# === Project ===

set(CMAKE_CXX_STANDARD 11)
if(LLGL_UWP_PLATFORM)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 11)
endif()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Expand Down Expand Up @@ -181,7 +186,7 @@ endfunction()
# The resource files must be located in the example media folder,
# i.e. either in "examples/Media/Textures/" or "examples/Media/Models/".
# Example:
# add_project_resource_files(MyProjectFiles ")
# add_project_resource_files(MyProjectFiles ModelAssets-*.obj TextureAsset-1.jpg")
function(add_project_resource_files OUTPUT_LIST)
# Iterate over all input filenames and expand their paths depending on their file extensions
set(ResourceFiles "")
Expand Down Expand Up @@ -397,16 +402,18 @@ option(LLGL_BUILD_EXAMPLES "Include example projects" OFF)

option(LLGL_BUILD_RENDERER_NULL "Include Null renderer project" ON)

if(LLGL_MOBILE_PLATFORM)
option(LLGL_BUILD_RENDERER_OPENGLES3 "Include OpenGLES 3 renderer project" ON)
else()
option(LLGL_BUILD_RENDERER_OPENGL "Include OpenGL renderer project" ON)
if(NOT LLGL_UWP_PLATFORM)
if(LLGL_MOBILE_PLATFORM)
option(LLGL_BUILD_RENDERER_OPENGLES3 "Include OpenGLES 3 renderer project" ON)
else()
option(LLGL_BUILD_RENDERER_OPENGL "Include OpenGL renderer project" ON)
endif()
endif()

if(APPLE)
option(LLGL_MACOS_ENABLE_COREVIDEO "Enable CoreVideo framework (for refresh rate of built-in displays)" ON)
option(LLGL_BUILD_RENDERER_METAL "Include Metal renderer project (experimental)" OFF)
else()
elseif(NOT LLGL_UWP_PLATFORM)
option(LLGL_BUILD_RENDERER_VULKAN "Include Vulkan renderer project (experimental)" OFF)
endif()

Expand Down Expand Up @@ -511,8 +518,13 @@ if(LLGL_ENABLE_DEBUG_LAYER)
endif()

if(WIN32)
find_source_files(FilesPlatform CXX "${PROJECT_SOURCE_DIR}/sources/Platform/Win32")
find_source_files(FilesIncludePlatform CXX "${PROJECT_INCLUDE_DIR}/LLGL/Platform/Win32")
if(LLGL_UWP_PLATFORM)
find_source_files(FilesPlatform CXX "${PROJECT_SOURCE_DIR}/sources/Platform/UWP")
find_source_files(FilesIncludePlatform CXX "${PROJECT_INCLUDE_DIR}/LLGL/Platform/UWP")
else()
find_source_files(FilesPlatform CXX "${PROJECT_SOURCE_DIR}/sources/Platform/Win32")
find_source_files(FilesIncludePlatform CXX "${PROJECT_INCLUDE_DIR}/LLGL/Platform/Win32")
endif()
else()
set(PlatformPosixDir "${PROJECT_SOURCE_DIR}/sources/Platform/POSIX")
if(APPLE)
Expand Down Expand Up @@ -664,6 +676,8 @@ elseif(APPLE)
endif()
elseif(UNIX)
target_link_libraries(LLGL X11 pthread Xrandr)
#elseif(LLGL_UWP_PLATFORM)
# set_target_properties(LLGL PROPERTIES VS_WINRT_REFERENCES "Windows.Foundation.UniversalApiContract")
endif()

set_property(GLOBAL PROPERTY LLGL_GLOBAL_MODULE_LIST LLGL)
Expand Down Expand Up @@ -702,7 +716,9 @@ if(LLGL_BUILD_RENDERER_DIRECT3D12)
add_subdirectory(sources/Renderer/Direct3D12)
endif()

if(LLGL_BUILD_STATIC_LIB)
# Static libs must all be linked to the final apps (LLGL_BUILD_STATIC_LIB).
# Also UWP apps need references to all loaded modules (LLGL_UWP_PLATFORM).
if(LLGL_BUILD_STATIC_LIB OR LLGL_UWP_PLATFORM)
get_property(LLGL_MODULE_LIBS GLOBAL PROPERTY LLGL_GLOBAL_MODULE_LIST)
else()
set(LLGL_MODULE_LIBS LLGL)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ with Introduction, Hello Triangle Tutorial, and Extensibility Example with [GLFW
| Platform | CI | D3D12 | D3D11 | Vulkan | GL/GLES3 | Metal |
|----------|:--:|:-----:|:-----:|:------:|:--------:|:-----:|
| <img src="docu/Icons/windows.svg" height="20" /> Windows | <p>[![MSVC16+ CI](https://github.com/LukasBanana/LLGL/actions/workflows/ci_windows.yml/badge.svg)](https://github.com/LukasBanana/LLGL/actions/workflows/ci_windows.yml)</p> <p>[![MSVC14 CI](https://ci.appveyor.com/api/projects/status/j09x8n07u3byfky0?svg=true)](https://ci.appveyor.com/project/LukasBanana/llgl)</p> | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | N/A |
| <img src="docu/Icons/windows.svg" height="20" /> UWP | N/A | :heavy_check_mark: | :heavy_check_mark: | N/A | N/A | N/A |
| <img src="docu/Icons/linux.svg" height="20" /> GNU/Linux | [![GNU/Linux CI](https://github.com/LukasBanana/LLGL/actions/workflows/ci_linux.yml/badge.svg)](https://github.com/LukasBanana/LLGL/actions/workflows/ci_linux.yml) | N/A | N/A | :heavy_check_mark: | :heavy_check_mark: | N/A |
| <img src="docu/Icons/macos.svg" height="20" /> macOS | [![macOS CI](https://github.com/LukasBanana/LLGL/actions/workflows/ci_macos.yml/badge.svg)](https://github.com/LukasBanana/LLGL/actions/workflows/ci_macos.yml) | N/A | N/A | N/A | :heavy_check_mark: | :heavy_check_mark: |
| <img src="docu/Icons/ios.svg" height="20" /> iOS | [![iOS CI](https://github.com/LukasBanana/LLGL/actions/workflows/ci_ios.yml/badge.svg)](https://github.com/LukasBanana/LLGL/actions/workflows/ci_ios.yml) | N/A | N/A | N/A | :heavy_check_mark: | :heavy_check_mark: |
Expand Down
2 changes: 2 additions & 0 deletions cmake/Toolchains/Toolchain.UWP-10_0.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(CMAKE_SYSTEM_NAME WindowsStore CACHE INTERNAL "")
set(CMAKE_SYSTEM_VERSION 10.0 CACHE INTERNAL "")
2 changes: 2 additions & 0 deletions cmake/Toolchains/Toolchain.UWP-8_0.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(CMAKE_SYSTEM_NAME WindowsStore CACHE INTERNAL "")
set(CMAKE_SYSTEM_VERSION 8.0 CACHE INTERNAL "")
2 changes: 2 additions & 0 deletions cmake/Toolchains/Toolchain.UWP-8_1.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(CMAKE_SYSTEM_NAME WindowsStore CACHE INTERNAL "")
set(CMAKE_SYSTEM_VERSION 8.1 CACHE INTERNAL "")
52 changes: 29 additions & 23 deletions examples/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ find_project_source_files( FilesExample_Tessellation "${EXAMPLE_CPP_PROJE
find_project_source_files( FilesExample_Texturing "${EXAMPLE_CPP_PROJECTS_DIR}/Texturing" )
find_project_source_files( FilesExample_VolumeRendering "${EXAMPLE_CPP_PROJECTS_DIR}/VolumeRendering" )

find_project_source_files( FilesExample_HelloUWP "${EXAMPLE_CPP_PROJECTS_DIR}/HelloUWP" )

# Append extra resources for mobile platforms
if(LLGL_IOS_PLATFORM)
add_project_resource_files(FilesExample_Fonts
Expand Down Expand Up @@ -142,30 +144,34 @@ if(LLGL_BUILD_EXAMPLES)
endif()

# Common examples
add_llgl_example_project(Example_Animation CXX "${FilesExample_Animation}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_ClothPhysics CXX "${FilesExample_ClothPhysics}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_ComputeShader CXX "${FilesExample_ComputeShader}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Fonts CXX "${FilesExample_Fonts}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_HelloTriangle CXX "${FilesExample_HelloTriangle}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Instancing CXX "${FilesExample_Instancing}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Mapping CXX "${FilesExample_Mapping}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_MultiThreading CXX "${FilesExample_MultiThreading}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_PBR CXX "${FilesExample_PBR}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_PostProcessing CXX "${FilesExample_PostProcessing}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Queries CXX "${FilesExample_Queries}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_RenderTarget CXX "${FilesExample_RenderTarget}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_ResourceBinding CXX "${FilesExample_ResourceBinding}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_ShadowMapping CXX "${FilesExample_ShadowMapping}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_StencilBuffer CXX "${FilesExample_StencilBuffer}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_StreamOutput CXX "${FilesExample_StreamOutput}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Tessellation CXX "${FilesExample_Tessellation}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Texturing CXX "${FilesExample_Texturing}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_VolumeRendering CXX "${FilesExample_VolumeRendering}" "${EXAMPLE_PROJECT_LIBS}")
if(LLGL_UWP_PLATFORM)
add_llgl_example_project(Example_HelloUWP CXX "${FilesExample_HelloUWP}" "${EXAMPLE_PROJECT_LIBS}")
else()
add_llgl_example_project(Example_Animation CXX "${FilesExample_Animation}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_ClothPhysics CXX "${FilesExample_ClothPhysics}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_ComputeShader CXX "${FilesExample_ComputeShader}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Fonts CXX "${FilesExample_Fonts}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_HelloTriangle CXX "${FilesExample_HelloTriangle}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Instancing CXX "${FilesExample_Instancing}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Mapping CXX "${FilesExample_Mapping}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_MultiThreading CXX "${FilesExample_MultiThreading}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_PBR CXX "${FilesExample_PBR}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_PostProcessing CXX "${FilesExample_PostProcessing}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Queries CXX "${FilesExample_Queries}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_RenderTarget CXX "${FilesExample_RenderTarget}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_ResourceBinding CXX "${FilesExample_ResourceBinding}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_ShadowMapping CXX "${FilesExample_ShadowMapping}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_StencilBuffer CXX "${FilesExample_StencilBuffer}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_StreamOutput CXX "${FilesExample_StreamOutput}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Tessellation CXX "${FilesExample_Tessellation}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_Texturing CXX "${FilesExample_Texturing}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_VolumeRendering CXX "${FilesExample_VolumeRendering}" "${EXAMPLE_PROJECT_LIBS}")

# Desktop specific examples
if(NOT LLGL_MOBILE_PLATFORM)
add_llgl_example_project(Example_MultiContext CXX "${FilesExample_MultiContext}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_MultiRenderer CXX "${FilesExample_MultiRenderer}" "${EXAMPLE_PROJECT_LIBS}")
# Desktop specific examples
if(NOT LLGL_MOBILE_PLATFORM)
add_llgl_example_project(Example_MultiContext CXX "${FilesExample_MultiContext}" "${EXAMPLE_PROJECT_LIBS}")
add_llgl_example_project(Example_MultiRenderer CXX "${FilesExample_MultiRenderer}" "${EXAMPLE_PROJECT_LIBS}")
endif()
endif()
endif(LLGL_BUILD_EXAMPLES)

Expand Down
Binary file added examples/Cpp/HelloUWP/HelloUWP.Example.PS.dxbc
Binary file not shown.
Binary file added examples/Cpp/HelloUWP/HelloUWP.Example.VS.dxbc
Binary file not shown.
Loading

0 comments on commit f2879ef

Please sign in to comment.