From dd6715962ecb15accdc6dc8d0be54a373e05eb1c Mon Sep 17 00:00:00 2001 From: Karl Robillard Date: Sat, 15 Apr 2023 21:17:07 -0400 Subject: [PATCH 1/4] Add Linux build files for viewer. This builds the tess version and has not been tried with skia. It still requires a few manual steps to get working as the rive library --with_rive_text option does not get set properly. --- build/linux/build_rive.sh | 41 ++++++++++++++++ dependencies/linux/get_earcut.sh | 1 + dependencies/linux/get_imgui.sh | 1 + dependencies/linux/get_libtess2.sh | 1 + dependencies/linux/get_premake5.sh | 1 + dependencies/linux/get_sokol.sh | 1 + dependencies/macosx/get_premake5.sh | 12 +++-- dependencies/macosx/get_sokol.sh | 9 ++-- tess/build/linux/build_tess.sh | 65 +++++++++++++++++++++++++ viewer/build/linux/build_viewer.sh | 73 +++++++++++++++++++++++++++++ viewer/build/premake5_viewer.lua | 12 +++++ 11 files changed, 211 insertions(+), 6 deletions(-) create mode 100755 build/linux/build_rive.sh create mode 120000 dependencies/linux/get_earcut.sh create mode 120000 dependencies/linux/get_imgui.sh create mode 120000 dependencies/linux/get_libtess2.sh create mode 120000 dependencies/linux/get_premake5.sh create mode 120000 dependencies/linux/get_sokol.sh create mode 100755 tess/build/linux/build_tess.sh create mode 100755 viewer/build/linux/build_viewer.sh diff --git a/build/linux/build_rive.sh b/build/linux/build_rive.sh new file mode 100755 index 00000000..db361938 --- /dev/null +++ b/build/linux/build_rive.sh @@ -0,0 +1,41 @@ +#!/bin/sh +set -e + +source ../../dependencies/linux/config_directories.sh + +CONFIG=debug +TOOLS= +TEXT= +for var in "$@"; do + if [[ $var = "release" ]]; then + CONFIG=release + fi + if [[ $var = "tools" ]]; then + TOOLS="--with_rive_tools" + fi + if [[ $var = "text" ]]; then + TEXT="--with_rive_text" + fi +done + +if [[ ! -f "$DEPENDENCIES/bin/premake5" ]]; then + pushd $DEPENDENCIES_SCRIPTS + ./get_premake5.sh + popd +fi + +export PREMAKE=$DEPENDENCIES/bin/premake5 +pushd .. + +$PREMAKE --file=./premake5.lua gmake2 $TOOLS $TEXT + +for var in "$@"; do + if [[ $var = "clean" ]]; then + make clean + make config=release clean + fi +done + +make config=$CONFIG -j4 + +popd diff --git a/dependencies/linux/get_earcut.sh b/dependencies/linux/get_earcut.sh new file mode 120000 index 00000000..9e7760e6 --- /dev/null +++ b/dependencies/linux/get_earcut.sh @@ -0,0 +1 @@ +../macosx/get_earcut.sh \ No newline at end of file diff --git a/dependencies/linux/get_imgui.sh b/dependencies/linux/get_imgui.sh new file mode 120000 index 00000000..b27085c0 --- /dev/null +++ b/dependencies/linux/get_imgui.sh @@ -0,0 +1 @@ +../macosx/get_imgui.sh \ No newline at end of file diff --git a/dependencies/linux/get_libtess2.sh b/dependencies/linux/get_libtess2.sh new file mode 120000 index 00000000..c7bcc2c2 --- /dev/null +++ b/dependencies/linux/get_libtess2.sh @@ -0,0 +1 @@ +../macosx/get_libtess2.sh \ No newline at end of file diff --git a/dependencies/linux/get_premake5.sh b/dependencies/linux/get_premake5.sh new file mode 120000 index 00000000..8615bec9 --- /dev/null +++ b/dependencies/linux/get_premake5.sh @@ -0,0 +1 @@ +../macosx/get_premake5.sh \ No newline at end of file diff --git a/dependencies/linux/get_sokol.sh b/dependencies/linux/get_sokol.sh new file mode 120000 index 00000000..9aa52378 --- /dev/null +++ b/dependencies/linux/get_sokol.sh @@ -0,0 +1 @@ +../macosx/get_sokol.sh \ No newline at end of file diff --git a/dependencies/macosx/get_premake5.sh b/dependencies/macosx/get_premake5.sh index bb9e65e6..90990d0c 100755 --- a/dependencies/macosx/get_premake5.sh +++ b/dependencies/macosx/get_premake5.sh @@ -5,11 +5,17 @@ if [[ -z "${DEPENDENCIES}" ]]; then exit 1 fi +if [ $(uname) = Linux ]; then + URL=https://github.com/premake/premake-core/releases/download/v5.0.0-beta2/premake-5.0.0-beta2-linux.tar.gz +else + URL=https://github.com/premake/premake-core/releases/download/v5.0.0-beta1/premake-5.0.0-beta1-macosx.tar.gz +fi + mkdir -p $DEPENDENCIES/bin echo Downloading Premake5 -curl https://github.com/premake/premake-core/releases/download/v5.0.0-beta1/premake-5.0.0-beta1-macosx.tar.gz -L -o $DEPENDENCIES//bin/premake_macosx.tar.gz +curl $URL -L -o $DEPENDENCIES//bin/premake_tmp.tar.gz cd $DEPENDENCIES/bin # Export premake5 into bin -tar -xvf premake_macosx.tar.gz 2>/dev/null +tar -xvf premake_tmp.tar.gz 2>/dev/null # Delete downloaded archive -rm premake_macosx.tar.gz +rm premake_tmp.tar.gz diff --git a/dependencies/macosx/get_sokol.sh b/dependencies/macosx/get_sokol.sh index 241c1e18..2b0fe6f0 100755 --- a/dependencies/macosx/get_sokol.sh +++ b/dependencies/macosx/get_sokol.sh @@ -15,10 +15,13 @@ if [ ! -d sokol ]; then echo "Cloning sokol." git clone $SOKOL_REPO - if [ $(arch) == arm64 ]; then - SOKOL_SHDC=https://github.com/floooh/sokol-tools-bin/raw/master/bin/osx_arm64/sokol-shdc + SOKOL_BIN=https://github.com/floooh/sokol-tools-bin/raw/master/bin + if [ $(uname -s) == Linux ]; then + SOKOL_SHDC=$SOKOL_BIN/linux/sokol-shdc + elif [ $(arch) == arm64 ]; then + SOKOL_SHDC=$SOKOL_BIN/osx_arm64/sokol-shdc else - SOKOL_SHDC=https://github.com/floooh/sokol-tools-bin/raw/master/bin/osx/sokol-shdc + SOKOL_SHDC=$SOKOL_BIN/osx/sokol-shdc fi curl $SOKOL_SHDC -L -o ./bin/sokol-shdc chmod +x ./bin/sokol-shdc diff --git a/tess/build/linux/build_tess.sh b/tess/build/linux/build_tess.sh new file mode 100755 index 00000000..f1b03e31 --- /dev/null +++ b/tess/build/linux/build_tess.sh @@ -0,0 +1,65 @@ +#!/bin/sh +set -e + +source ../../../dependencies/linux/config_directories.sh + +if [[ ! -f "$DEPENDENCIES/bin/premake5" ]]; then + pushd $DEPENDENCIES_SCRIPTS + ./get_premake5.sh + popd +fi + +if [[ ! -d "$DEPENDENCIES/sokol" ]]; then + pushd $DEPENDENCIES_SCRIPTS + ./get_sokol.sh + popd +fi + +if [[ ! -d "$DEPENDENCIES/earcut.hpp" ]]; then + pushd $DEPENDENCIES_SCRIPTS + ./get_earcut.sh + popd +fi + +if [[ ! -d "$DEPENDENCIES/libtess2" ]]; then + pushd $DEPENDENCIES_SCRIPTS + ./get_libtess2.sh + popd +fi + +export PREMAKE=$DEPENDENCIES/bin/premake5 +pushd .. + +CONFIG=debug +GRAPHICS=gl +TEST=false +for var in "$@"; do + if [[ $var = "release" ]]; then + CONFIG=release + fi + if [[ $var = "gl" ]]; then + GRAPHICS=gl + fi + if [[ $var = "test" ]]; then + TEST=true + fi +done + +$PREMAKE --scripts=../../build --file=./premake5_tess.lua gmake2 --graphics=$GRAPHICS --with_rive_tools + +for var in "$@"; do + if [[ $var = "clean" ]]; then + make clean + make config=release clean + fi +done + +# compile shaders +$DEPENDENCIES/bin/sokol-shdc --input ../src/sokol/shader.glsl --output ../src/sokol/generated/shader.h --slang glsl330:hlsl5:metal_macos:metal_ios:metal_sim:glsl300es:glsl100 + +make config=$CONFIG -j4 + +if [[ $TEST = "true" ]]; then + linux/bin/$CONFIG/rive_tess_tests +fi +popd diff --git a/viewer/build/linux/build_viewer.sh b/viewer/build/linux/build_viewer.sh new file mode 100755 index 00000000..087e5892 --- /dev/null +++ b/viewer/build/linux/build_viewer.sh @@ -0,0 +1,73 @@ +#!/bin/sh +set -e + +source ../../../dependencies/linux/config_directories.sh + +CONFIG=debug +GRAPHICS=gl +RENDERER=tess + +for var in "$@"; do + if [[ $var = "release" ]]; then + CONFIG=release + fi + if [[ $var = "gl" ]]; then + GRAPHICS=gl + fi + if [[ $var = "tess" ]]; then + RENDERER=tess + fi + if [[ $var = "skia" ]]; then + RENDERER=skia + fi +done + +if [[ ! -f "$DEPENDENCIES/bin/premake5" ]]; then + pushd $DEPENDENCIES_SCRIPTS + ./get_premake5.sh + popd +fi + +if [[ ! -d "$DEPENDENCIES/imgui" ]]; then + pushd $DEPENDENCIES_SCRIPTS + ./get_imgui.sh + popd +fi + +if [ $RENDERER = "skia" ]; then + pushd ../../../skia/renderer/build/linux + ./build_skia_renderer.sh text $@ + popd +fi + +if [ $RENDERER = "tess" ]; then + pushd ../../../tess/build/linux + ./build_tess.sh $@ + popd +fi + +export PREMAKE=$DEPENDENCIES/bin/premake5 + +pushd .. + +$PREMAKE --scripts=../../build --file=./premake5_viewer.lua gmake2 --graphics=$GRAPHICS --renderer=$RENDERER --with_rive_tools --with_rive_text + +for var in "$@"; do + if [[ $var = "clean" ]]; then + make clean + make config=release clean + fi +done + +make config=$CONFIG -j4 + +popd + +for var in "$@"; do + if [[ $var = "run" ]]; then + bin/$CONFIG/$RENDERER/$GRAPHICS/rive_viewer + fi + if [[ $var = "lldb" ]]; then + lldb bin/$CONFIG/$RENDERER/$GRAPHICS/rive_viewer + fi +done diff --git a/viewer/build/premake5_viewer.lua b/viewer/build/premake5_viewer.lua index 3e5f9fb1..07ca559d 100644 --- a/viewer/build/premake5_viewer.lua +++ b/viewer/build/premake5_viewer.lua @@ -67,6 +67,18 @@ do '-fno-rtti' } + filter { + 'system:linux' + } + do + links { + 'GL', + 'Xcursor', + 'Xi', + 'X11' + } + end + filter { 'system:macosx' } From f8d9a23b72c5993e86406f6f0fead2d56e488166 Mon Sep 17 00:00:00 2001 From: Karl Robillard Date: Sat, 15 Apr 2023 23:18:15 -0400 Subject: [PATCH 2/4] Fix clang 15.0.7-2.fc37 compiler errors. Replace vector because of this error: stl_vector.h:435:7: error: static assertion failed due to requirement 'is_same::value': std::vector must have a non-const, non-volatile value_type --- viewer/include/viewer/viewer_content.hpp | 1 + viewer/src/tess/bitmap_decoder.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/viewer/include/viewer/viewer_content.hpp b/viewer/include/viewer/viewer_content.hpp index ad7ba607..03f4cfa3 100644 --- a/viewer/include/viewer/viewer_content.hpp +++ b/viewer/include/viewer/viewer_content.hpp @@ -5,6 +5,7 @@ #ifndef _RIVE_VIEWER_CONTENT_HPP_ #define _RIVE_VIEWER_CONTENT_HPP_ +#include #include "rive/span.hpp" #include "rive/refcnt.hpp" diff --git a/viewer/src/tess/bitmap_decoder.cpp b/viewer/src/tess/bitmap_decoder.cpp index b438740f..405f8062 100644 --- a/viewer/src/tess/bitmap_decoder.cpp +++ b/viewer/src/tess/bitmap_decoder.cpp @@ -1,6 +1,6 @@ #ifdef RIVE_RENDERER_TESS #include "viewer/tess/bitmap_decoder.hpp" -#include +#include Bitmap::Bitmap(uint32_t width, uint32_t height, @@ -41,7 +41,8 @@ using BitmapDecoder = std::unique_ptr (*)(rive::Span byte struct ImageFormat { const char* name; - std::vector fingerprint; + uint8_t fingerprintSize; + uint8_t fingerprint[4]; BitmapDecoder decodeImage; }; @@ -49,17 +50,17 @@ std::unique_ptr Bitmap::decode(rive::Span bytes) { static ImageFormat decoders[] = { { - "png", + "png", 4, {0x89, 0x50, 0x4E, 0x47}, DecodePng, }, { - "jpeg", + "jpeg", 3, {0xFF, 0xD8, 0xFF}, DecodeJpeg, }, { - "webp", + "webp", 3, {0x52, 0x49, 0x46}, DecodeWebP, }, @@ -71,14 +72,14 @@ std::unique_ptr Bitmap::decode(rive::Span bytes) // Immediately discard decoders with fingerprints that are longer than // the file buffer. - if (recognizer.fingerprint.size() > bytes.size()) + if (recognizer.fingerprintSize > bytes.size()) { continue; } // If the fingerprint doesn't match, discrd this decoder. These are all bytes so .size() is // fine here. - if (std::memcmp(fingerprint.data(), bytes.data(), fingerprint.size()) != 0) + if (std::memcmp(recognizer.fingerprint, bytes.data(), recognizer.fingerprintSize) != 0) { continue; } @@ -117,4 +118,4 @@ void Bitmap::pixelFormat(PixelFormat format) m_Bytes = std::move(nextBytes); m_PixelFormat = format; } -#endif \ No newline at end of file +#endif From be8fe3c5dc764ac5572e24f6ca7901d9ec4329af Mon Sep 17 00:00:00 2001 From: Karl Robillard Date: Sun, 16 Apr 2023 00:21:36 -0400 Subject: [PATCH 3/4] Fix SOKOL_IMPL. --- viewer/src/platform/imgui_sokol_impl.cpp | 3 +-- viewer/src/viewer.cpp | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/viewer/src/platform/imgui_sokol_impl.cpp b/viewer/src/platform/imgui_sokol_impl.cpp index 8888b324..77a5531b 100644 --- a/viewer/src/platform/imgui_sokol_impl.cpp +++ b/viewer/src/platform/imgui_sokol_impl.cpp @@ -1,5 +1,4 @@ #include "sokol_app.h" #include "sokol_gfx.h" -#define SOKOL_IMPL #include "imgui.h" -#include "util/sokol_imgui.h" \ No newline at end of file +#include "util/sokol_imgui.h" diff --git a/viewer/src/viewer.cpp b/viewer/src/viewer.cpp index dc343fa6..2fcf4ab8 100644 --- a/viewer/src/viewer.cpp +++ b/viewer/src/viewer.cpp @@ -5,6 +5,7 @@ #include "rive/shapes/paint/color.hpp" // Graphics and UI abstraction +#define SOKOL_IMPL #include "sokol_app.h" #include "sokol_gfx.h" #include "sokol_glue.h" @@ -217,4 +218,4 @@ sapp_desc sokol_main(int argc, char* argv[]) #endif .width = 800, .height = 600, .icon.sokol_default = true, .gl_force_gles2 = true, }; -} \ No newline at end of file +} From 310fde54f9a2cbe92d1fece7c2609f7414764b60 Mon Sep 17 00:00:00 2001 From: Karl Robillard Date: Sun, 16 Apr 2023 11:13:42 -0400 Subject: [PATCH 4/4] Comment out missing bindGraphicsContext on Linux. --- viewer/src/viewer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/viewer/src/viewer.cpp b/viewer/src/viewer.cpp index 2fcf4ab8..22d80f15 100644 --- a/viewer/src/viewer.cpp +++ b/viewer/src/viewer.cpp @@ -131,7 +131,9 @@ static void event(const sapp_event* ev) case SAPP_EVENTTYPE_FILES_DROPPED: { // Do this to make sure the graphics is bound. +#ifndef __linux bindGraphicsContext(); +#endif // get the number of files and their paths like this: const int numDroppedFiles = sapp_get_num_dropped_files();