Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MoltenVK integration #761

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,17 @@ endif()
set(SDL2_INCLUDE_DIR ${THIRDPARTY_DIR}/sdl2-2.0.3/include)

## Vulkan
if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
## osx32 and linux32 cmake can spot each others' .so and .a files, so keep them apart
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_library(VULKAN_LIBRARY
NAMES
MoltenVK
PATHS
${THIRDPARTY_DIR}/vulkan-1.0.49.0/lib/osx32/MoltenVK/macOS
NO_DEFAULT_PATH
)
set(VULKAN_INCLUDE_DIR ${THIRDPARTY_DIR}/vulkan-1.0.49.0/lib/osx32/MoltenVK/include)
else()
find_library(VULKAN_LIBRARY
NAMES
vulkan-1
Expand Down Expand Up @@ -227,26 +237,22 @@ file(GLOB SHARED_SRC_FILES

include_directories(
.
${VULKAN_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${SDL2_INCLUDE_DIR}
${QT_INCLUDE_DIRS}
${OPENVR_INCLUDE_DIR}
)

if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
include_directories(${VULKAN_INCLUDE_DIR})
endif()

# -----------------------------------------------------------------------------
## SUBDIRECTORIES ##

add_subdirectory(driver_sample)
add_subdirectory(hellovr_opengl)
if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
add_subdirectory(hellovr_vulkan)
endif()
add_subdirectory(hellovr_vulkan)
add_subdirectory(helloworldoverlay)
add_subdirectory(tracked_camera_openvr_sample)


# -----------------------------------------------------------------------------
39 changes: 28 additions & 11 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,41 @@ On Windows x64, you will need the SDL2 runtime library.
We will use the command-line on Unix and [Git Bash](https://git-for-windows.github.io/) on Windows.

First, move from the repository root to the samples directory to create a build directory:
```
cd samples
mkdir build; cd build
```

cd samples
mkdir build
cd build

Then, depending on your system:

### Unix

Generate the CMake cache using Makefile:
```
cmake .. -G Makefile -DCMAKE_PREFIX_PATH=/opt/Qt/5.6/gcc_64/lib/cmake -DCMAKE_BUILD_TYPE=Release
```

To build type:
```
make -j4
```
cmake .. -G Makefile -DCMAKE_PREFIX_PATH=/opt/Qt/5.6/gcc_64/lib/cmake -DCMAKE_BUILD_TYPE=Release

To build:

make -j4

### macOS

Generate the Xcode project:

cmake .. -G Xcode -DCMAKE_PREFIX_PATH=<path-to-Qt>/5.6/clang_64/lib/cmake -DCMAKE_BUILD_TYPE=Release

On macOS, the `hellovr_vulkan` sample uses the MoltenVK Vulkan driver. To run this sample, install
`Molten` in the same directory as `openvr`:

Molten/
openvr/

or if you have installed `Molten` somewhere else, modify the sample's symlink to your MoltenVK installation:

cd openvr/samples/thirdparty/vulkan-1.0.49.0/lib/osx32
ln -sfn <path-to-Molten-installation>/MoltenVK

Then open the `samples/build/openvr_samples.xcodeproj` *Xcode* project and build and run the appropriate target.


### Windows
Expand Down
1 change: 1 addition & 0 deletions samples/bin/osx32/libMoltenVK.dylib
1 change: 1 addition & 0 deletions samples/bin/osx32/libSDL2.dylib
4 changes: 1 addition & 3 deletions samples/hellovr_opengl/hellovr_opengl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <GL/glew.h>
#include <SDL_opengl.h>
#if defined( OSX )
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
#include <OpenGL/glu.h>
// Apple's version of glut.h #undef's APIENTRY, redefine it
#define APIENTRY
Expand Down Expand Up @@ -235,7 +233,7 @@ void dprintf( const char *fmt, ... )
char buffer[ 2048 ];

va_start( args, fmt );
vsprintf_s( buffer, fmt, args );
sprintf_s( buffer, sizeof( buffer ), fmt, args );
va_end( args );

if ( g_bPrintf )
Expand Down
43 changes: 38 additions & 5 deletions samples/hellovr_vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
set(TARGET_NAME hellovr_vulkan)

add_executable(${TARGET_NAME}
${SHARED_SRC_FILES}
hellovr_vulkan_main.cpp
)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_compile_options(-x objective-c++)

find_library(FOUNDATION_FRAMEWORK Foundation)
mark_as_advanced(FOUNDATION_FRAMEWORK)
set(EXTRA_LIBS ${EXTRA_LIBS} ${FOUNDATION_FRAMEWORK})

find_library(APPKIT_FRAMEWORK AppKit)
mark_as_advanced(APPKIT_FRAMEWORK)
set(EXTRA_LIBS ${EXTRA_LIBS} ${APPKIT_FRAMEWORK})

find_library(METAL_FRAMEWORK Metal)
mark_as_advanced(METAL_FRAMEWORK)
set(EXTRA_LIBS ${EXTRA_LIBS} ${METAL_FRAMEWORK})

find_library(IOSURFACE_FRAMEWORK IOSurface)
mark_as_advanced(IOSURFACE_FRAMEWORK)
set(EXTRA_LIBS ${EXTRA_LIBS} ${IOSURFACE_FRAMEWORK})

find_library(QUARTZCORE_FRAMEWORK QuartzCore)
mark_as_advanced(QUARTZCORE_FRAMEWORK)
set(EXTRA_LIBS ${EXTRA_LIBS} ${QUARTZCORE_FRAMEWORK})

add_executable(${TARGET_NAME}
${SHARED_SRC_FILES}
osx/SDL_cocoametalview.h
osx/SDL_cocoametalview.m
hellovr_vulkan_main.cpp
)

else()
add_executable(${TARGET_NAME}
${SHARED_SRC_FILES}
hellovr_vulkan_main.cpp
)
endif()


target_link_libraries(${TARGET_NAME}
${SDL2_LIBRARIES}
${VULKAN_LIBRARY}
${SDL2_LIBRARIES}
${OPENVR_LIBRARIES}
${CMAKE_DL_LIBS}
${EXTRA_LIBS}
Expand Down
Loading