Skip to content

Commit

Permalink
Vulkan embedder GLFW example (flutter#31213)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored Feb 3, 2022
1 parent 82aad2e commit 7e94ad5
Show file tree
Hide file tree
Showing 7 changed files with 914 additions and 2 deletions.
5 changes: 4 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ group("flutter") {

# Ensure the example for a sample embedder compiles.
if (build_embedder_examples) {
public_deps += [ "//flutter/examples/glfw" ]
public_deps += [
"//flutter/examples/glfw",
"//flutter/examples/vulkan_glfw",
]
}

# If enbaled, compile the SDK / snapshot.
Expand Down
1 change: 1 addition & 0 deletions examples/vulkan_glfw/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debug/
16 changes: 16 additions & 0 deletions examples/vulkan_glfw/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

executable("vulkan_glfw") {
output_name = "embedder_example_vulkan"

sources = [ "src/main.cc" ]

configs += [ "//flutter/vulkan:vulkan_config" ]

deps = [
"//flutter/shell/platform/embedder:embedder",
"//third_party/glfw",
]
}
64 changes: 64 additions & 0 deletions examples/vulkan_glfw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
cmake_minimum_required(VERSION 3.15)
project(FlutterEmbedderVulkanGLFW)

set(CMAKE_CXX_STANDARD 17)

# Primary target

set(EXE_NAME embedder_example_vulkan)

file(GLOB_RECURSE SOURCE_FILES "src/*.cc" "src/*.h")
add_executable(${EXE_NAME} ${SOURCE_FILES})


# Dependency: Vulkan SDK

# Override the SDK location by using the VULKAN_SDK environment variable.
# The VULKAN_SDK path should contain `include/vulkan/vulkan.hpp`.
#
# MacOS MoltenVK Vulkan SDK environment example:
# export VULKAN_SDK=~/VulkanSDK/1.2.198.1/macOS
# export VK_LOADER_DEBUG=all
# export VK_ICD_FILENAMES=$VULKAN_SDK/share/vulkan/icd.d/MoltenVK_icd.json
# export VK_LAYER_PATH=$VULKAN_SDK/share/vulkan/explicit_layer.d
# export DYLD_LIBRARY_PATH=$VULKAN_SDK/lib:$DYLD_LIBRARY_PATH

find_package(Vulkan REQUIRED)
target_include_directories(${EXE_NAME} PRIVATE ${Vulkan_INCLUDE_DIRS})
target_link_libraries(${EXE_NAME} PRIVATE Vulkan::Vulkan)


# Dependency: GLFW

set(GLFW_REPOSITORY ${CMAKE_SOURCE_DIR}/../../../third_party/glfw)

set(BUILD_SHARED_LIBS OFF)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_VULKAN_STATIC OFF CACHE BOOL "" FORCE)
add_subdirectory(${GLFW_REPOSITORY} build_glfw)

target_link_libraries(${EXE_NAME} PRIVATE glfw)
target_include_directories(${EXE_NAME} PRIVATE $(GLFW_REPOSITORY)/include)


# Dependency: Flutter Engine

# This is assuming you've built a local version of the Flutter Engine. If you
# downloaded yours from the internet you'll have to change this.
set(EMBEDDER_H_DIR ${CMAKE_SOURCE_DIR}/../../shell/platform/embedder)
set(FLUTTER_OUT_DIR ${CMAKE_SOURCE_DIR}/../../../out/host_debug_unopt)

find_library(FLUTTER_LIB flutter_engine PATHS ${FLUTTER_OUT_DIR})

target_link_libraries(${EXE_NAME} PRIVATE ${FLUTTER_LIB})
target_include_directories(${EXE_NAME} PRIVATE ${EMBEDDER_H_DIR})

# Copy the flutter library here since the shared library
# name is `./libflutter_engine.dylib`.
add_custom_command(
TARGET ${EXE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${FLUTTER_LIB}
${CMAKE_CURRENT_BINARY_DIR})
27 changes: 27 additions & 0 deletions examples/vulkan_glfw/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -xe

#################################################################
# Make the host C++ project.
#################################################################
cmake -Bdebug -DCMAKE_BUILD_TYPE=Debug
pushd debug > /dev/null
make

#################################################################
# Make the guest Flutter project.
#################################################################
if [ ! -d myapp ]; then
flutter create myapp
fi
pushd myapp > /dev/null
#cp ../../main.dart lib/main.dart
flutter build bundle
popd > /dev/null

#################################################################
# Run the Flutter Engine Embedder
#################################################################
./embedder_example_vulkan ./myapp ../../../../third_party/icu/common/icudtl.dat

popd > /dev/null
Loading

0 comments on commit 7e94ad5

Please sign in to comment.