Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7e94ad5

Browse files
authored
Vulkan embedder GLFW example (#31213)
1 parent 82aad2e commit 7e94ad5

File tree

7 files changed

+914
-2
lines changed

7 files changed

+914
-2
lines changed

BUILD.gn

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ group("flutter") {
8282

8383
# Ensure the example for a sample embedder compiles.
8484
if (build_embedder_examples) {
85-
public_deps += [ "//flutter/examples/glfw" ]
85+
public_deps += [
86+
"//flutter/examples/glfw",
87+
"//flutter/examples/vulkan_glfw",
88+
]
8689
}
8790

8891
# If enbaled, compile the SDK / snapshot.

examples/vulkan_glfw/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
debug/

examples/vulkan_glfw/BUILD.gn

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
executable("vulkan_glfw") {
6+
output_name = "embedder_example_vulkan"
7+
8+
sources = [ "src/main.cc" ]
9+
10+
configs += [ "//flutter/vulkan:vulkan_config" ]
11+
12+
deps = [
13+
"//flutter/shell/platform/embedder:embedder",
14+
"//third_party/glfw",
15+
]
16+
}

examples/vulkan_glfw/CMakeLists.txt

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(FlutterEmbedderVulkanGLFW)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
6+
# Primary target
7+
8+
set(EXE_NAME embedder_example_vulkan)
9+
10+
file(GLOB_RECURSE SOURCE_FILES "src/*.cc" "src/*.h")
11+
add_executable(${EXE_NAME} ${SOURCE_FILES})
12+
13+
14+
# Dependency: Vulkan SDK
15+
16+
# Override the SDK location by using the VULKAN_SDK environment variable.
17+
# The VULKAN_SDK path should contain `include/vulkan/vulkan.hpp`.
18+
#
19+
# MacOS MoltenVK Vulkan SDK environment example:
20+
# export VULKAN_SDK=~/VulkanSDK/1.2.198.1/macOS
21+
# export VK_LOADER_DEBUG=all
22+
# export VK_ICD_FILENAMES=$VULKAN_SDK/share/vulkan/icd.d/MoltenVK_icd.json
23+
# export VK_LAYER_PATH=$VULKAN_SDK/share/vulkan/explicit_layer.d
24+
# export DYLD_LIBRARY_PATH=$VULKAN_SDK/lib:$DYLD_LIBRARY_PATH
25+
26+
find_package(Vulkan REQUIRED)
27+
target_include_directories(${EXE_NAME} PRIVATE ${Vulkan_INCLUDE_DIRS})
28+
target_link_libraries(${EXE_NAME} PRIVATE Vulkan::Vulkan)
29+
30+
31+
# Dependency: GLFW
32+
33+
set(GLFW_REPOSITORY ${CMAKE_SOURCE_DIR}/../../../third_party/glfw)
34+
35+
set(BUILD_SHARED_LIBS OFF)
36+
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
37+
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
38+
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
39+
set(GLFW_VULKAN_STATIC OFF CACHE BOOL "" FORCE)
40+
add_subdirectory(${GLFW_REPOSITORY} build_glfw)
41+
42+
target_link_libraries(${EXE_NAME} PRIVATE glfw)
43+
target_include_directories(${EXE_NAME} PRIVATE $(GLFW_REPOSITORY)/include)
44+
45+
46+
# Dependency: Flutter Engine
47+
48+
# This is assuming you've built a local version of the Flutter Engine. If you
49+
# downloaded yours from the internet you'll have to change this.
50+
set(EMBEDDER_H_DIR ${CMAKE_SOURCE_DIR}/../../shell/platform/embedder)
51+
set(FLUTTER_OUT_DIR ${CMAKE_SOURCE_DIR}/../../../out/host_debug_unopt)
52+
53+
find_library(FLUTTER_LIB flutter_engine PATHS ${FLUTTER_OUT_DIR})
54+
55+
target_link_libraries(${EXE_NAME} PRIVATE ${FLUTTER_LIB})
56+
target_include_directories(${EXE_NAME} PRIVATE ${EMBEDDER_H_DIR})
57+
58+
# Copy the flutter library here since the shared library
59+
# name is `./libflutter_engine.dylib`.
60+
add_custom_command(
61+
TARGET ${EXE_NAME} POST_BUILD
62+
COMMAND ${CMAKE_COMMAND} -E copy
63+
${FLUTTER_LIB}
64+
${CMAKE_CURRENT_BINARY_DIR})

examples/vulkan_glfw/run.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -xe
3+
4+
#################################################################
5+
# Make the host C++ project.
6+
#################################################################
7+
cmake -Bdebug -DCMAKE_BUILD_TYPE=Debug
8+
pushd debug > /dev/null
9+
make
10+
11+
#################################################################
12+
# Make the guest Flutter project.
13+
#################################################################
14+
if [ ! -d myapp ]; then
15+
flutter create myapp
16+
fi
17+
pushd myapp > /dev/null
18+
#cp ../../main.dart lib/main.dart
19+
flutter build bundle
20+
popd > /dev/null
21+
22+
#################################################################
23+
# Run the Flutter Engine Embedder
24+
#################################################################
25+
./embedder_example_vulkan ./myapp ../../../../third_party/icu/common/icudtl.dat
26+
27+
popd > /dev/null

0 commit comments

Comments
 (0)