2013-09-19 16:04:30 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# =============================================================================
|
|
|
|
# Copyright (c) 2011-2013 Bolero MURAKAMI
|
|
|
|
# https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
#
|
|
|
|
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
# =============================================================================
|
|
|
|
#
|
|
|
|
# requires: ImageMagick (http://www.imagemagick.org/script/index.php)
|
|
|
|
#
|
2013-09-19 17:40:19 +00:00
|
|
|
src="../../example/darkroom/two_spheres.hpp"
|
2013-09-19 16:04:30 +00:00
|
|
|
stagedir="darkroom"
|
|
|
|
width=16
|
|
|
|
height=16
|
|
|
|
tile_width=16
|
|
|
|
tile_height=16
|
|
|
|
force=0
|
|
|
|
|
2013-09-20 07:38:27 +00:00
|
|
|
args=`getopt -o s:S:w:h:W:H:f -l source:,stagedir:,width:,height:,tile-width:,tile-height:,force -- "$@"`
|
2013-09-19 16:04:30 +00:00
|
|
|
if [ "$?" -ne 0 ]; then
|
2013-09-20 07:38:27 +00:00
|
|
|
echo >&2 -e ": \e[31musage: $0 [-s|--source=file] [-S|--stagedir=path] [-w|--width=value] [-h|--height=value] [-W|--tile-width=value] [-H|--tile-height=value] [-f|-force]\e[m"
|
2013-09-19 16:04:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
eval set -- ${args}
|
|
|
|
while [ -n "$1" ]; do
|
|
|
|
case $1 in
|
|
|
|
-s|--source) src=$2; shift 2;;
|
2013-09-20 07:38:27 +00:00
|
|
|
-S|--stagedir) stagedir=$2; shift 2;;
|
2013-09-19 16:04:30 +00:00
|
|
|
-w|--width) width=$2; shift 2;;
|
|
|
|
-h|--height) height=$2; shift 2;;
|
|
|
|
-W|--tile-width) tile_width=$2; shift 2;;
|
|
|
|
-H|--tile-height) tile_height=$2; shift 2;;
|
2013-09-19 16:39:16 +00:00
|
|
|
-f|--force) force=1; shift;;
|
2013-09-19 16:04:30 +00:00
|
|
|
--) shift; break;;
|
|
|
|
*) echo >&2 -e ": \e[31munknown option($1) used.\e[m"; exit 1;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
echo ": settings"
|
2013-09-20 07:38:27 +00:00
|
|
|
echo ": source = \"${src}\""
|
|
|
|
echo ": stagedir = \"${stagedir}\""
|
2013-09-19 16:04:30 +00:00
|
|
|
echo ": width = ${width}"
|
|
|
|
echo ": height = ${height}"
|
|
|
|
echo ": tile-width = ${tile_width}"
|
|
|
|
echo ": tile-height = ${tile_height}"
|
|
|
|
echo ": force = ${force}"
|
|
|
|
|
2013-09-19 17:40:19 +00:00
|
|
|
if [ ! -f "${src}" -a ! -f "$(cd $(dirname $0); pwd)/${src}" ]; then
|
2013-09-20 07:38:27 +00:00
|
|
|
echo >&2 -e ": \e[31msource(${src}) not exists.\e[m"
|
2013-09-19 16:04:30 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d "${stagedir}" ]; then
|
|
|
|
if [ ${force} -eq 0 ]; then
|
2013-09-20 07:38:27 +00:00
|
|
|
echo >&2 -e ": \e[31mstagedir(${stagedir}) already exists.\e[m"
|
2013-09-19 16:04:30 +00:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
rm -f -r ${stagedir}/*
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
mkdir -p ${stagedir}
|
|
|
|
fi
|
|
|
|
|
2013-09-20 07:38:27 +00:00
|
|
|
echo ": start."
|
|
|
|
start=${SECONDS}
|
2013-09-19 16:04:30 +00:00
|
|
|
|
|
|
|
for ((y=0; y<height; y+=tile_height)); do
|
2013-09-20 07:38:27 +00:00
|
|
|
echo ": rendering(${y}/${height})..."
|
|
|
|
y_start=${SECONDS}
|
2013-09-19 16:04:30 +00:00
|
|
|
|
|
|
|
for ((x=0; x<width; x+=tile_width)); do
|
|
|
|
mkdir -p ${stagedir}/${y}/
|
2013-09-20 07:38:27 +00:00
|
|
|
binname=${stagedir}/${y}/${x}.out
|
2013-09-19 16:04:30 +00:00
|
|
|
g++ -o ${binname} -std=c++11 \
|
|
|
|
-DDARKROOM_SOURCE="\"${src}\"" \
|
|
|
|
-DDARKROOM_TOTAL_WIDTH=${width} \
|
|
|
|
-DDARKROOM_TOTAL_HEIGHT=${height} \
|
|
|
|
-DDARKROOM_TILE_WIDTH=${tile_width} \
|
|
|
|
-DDARKROOM_TILE_HEIGHT=${tile_height} \
|
|
|
|
-DDARKROOM_OFFSET_X=${x} \
|
|
|
|
-DDARKROOM_OFFSET_Y=${y} \
|
|
|
|
$(cd $(dirname $0); pwd)/darkcult.cpp && ${binname} > ${stagedir}/${y}/${x}.ppm
|
|
|
|
# rm ${binname}
|
2013-09-20 07:38:27 +00:00
|
|
|
done
|
|
|
|
pushd ${stagedir}/${y}/ > /dev/null
|
2013-09-19 16:04:30 +00:00
|
|
|
convert +append $(ls *.ppm | sort -n) ../${y}.ppm
|
2013-09-20 07:38:27 +00:00
|
|
|
popd > /dev/null
|
2013-09-19 16:04:30 +00:00
|
|
|
|
2013-09-20 07:38:27 +00:00
|
|
|
let "y_elapsed=${SECONDS}-${y_start}"
|
|
|
|
echo ": elapsed = ${y_elapsed}s"
|
|
|
|
done
|
|
|
|
pushd ${stagedir} > /dev/null
|
2013-09-19 16:04:30 +00:00
|
|
|
convert -append $(ls *.ppm | sort -n) out.ppm
|
2013-09-20 07:38:27 +00:00
|
|
|
popd > /dev/null
|
2013-09-19 16:04:30 +00:00
|
|
|
|
2013-09-20 07:38:27 +00:00
|
|
|
let "elapsed=${SECONDS}-${start}"
|
|
|
|
echo ": elapsed(total) = ${elapsed}s"
|
2013-09-19 17:40:19 +00:00
|
|
|
echo ": finished."
|