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

Linux viewer build #358

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
41 changes: 41 additions & 0 deletions build/linux/build_rive.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions dependencies/linux/get_earcut.sh
1 change: 1 addition & 0 deletions dependencies/linux/get_imgui.sh
1 change: 1 addition & 0 deletions dependencies/linux/get_libtess2.sh
1 change: 1 addition & 0 deletions dependencies/linux/get_premake5.sh
1 change: 1 addition & 0 deletions dependencies/linux/get_sokol.sh
12 changes: 9 additions & 3 deletions dependencies/macosx/get_premake5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 6 additions & 3 deletions dependencies/macosx/get_sokol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 65 additions & 0 deletions tess/build/linux/build_tess.sh
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions viewer/build/linux/build_viewer.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions viewer/build/premake5_viewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ do
'-fno-rtti'
}

filter {
'system:linux'
}
do
links {
'GL',
'Xcursor',
'Xi',
'X11'
}
end

filter {
'system:macosx'
}
Expand Down
1 change: 1 addition & 0 deletions viewer/include/viewer/viewer_content.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef _RIVE_VIEWER_CONTENT_HPP_
#define _RIVE_VIEWER_CONTENT_HPP_

#include <vector>
#include "rive/span.hpp"
#include "rive/refcnt.hpp"

Expand Down
3 changes: 1 addition & 2 deletions viewer/src/platform/imgui_sokol_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "sokol_app.h"
#include "sokol_gfx.h"
#define SOKOL_IMPL
#include "imgui.h"
#include "util/sokol_imgui.h"
#include "util/sokol_imgui.h"
17 changes: 9 additions & 8 deletions viewer/src/tess/bitmap_decoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef RIVE_RENDERER_TESS
#include "viewer/tess/bitmap_decoder.hpp"
#include <vector>
#include <cstring>

Bitmap::Bitmap(uint32_t width,
uint32_t height,
Expand Down Expand Up @@ -41,25 +41,26 @@ using BitmapDecoder = std::unique_ptr<Bitmap> (*)(rive::Span<const uint8_t> byte
struct ImageFormat
{
const char* name;
std::vector<const uint8_t> fingerprint;
uint8_t fingerprintSize;
uint8_t fingerprint[4];
BitmapDecoder decodeImage;
};

std::unique_ptr<Bitmap> Bitmap::decode(rive::Span<const uint8_t> 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,
},
Expand All @@ -71,14 +72,14 @@ std::unique_ptr<Bitmap> Bitmap::decode(rive::Span<const uint8_t> 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;
}
Expand Down Expand Up @@ -117,4 +118,4 @@ void Bitmap::pixelFormat(PixelFormat format)
m_Bytes = std::move(nextBytes);
m_PixelFormat = format;
}
#endif
#endif
5 changes: 4 additions & 1 deletion viewer/src/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -130,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();
Expand Down Expand Up @@ -217,4 +220,4 @@ sapp_desc sokol_main(int argc, char* argv[])
#endif
.width = 800, .height = 600, .icon.sokol_default = true, .gl_force_gles2 = true,
};
}
}