commit
0a31f94343
28 changed files with 3696 additions and 1148 deletions
|
|
@ -5,17 +5,17 @@
|
||||||
* NOTE: This example does not require any graphic device, it can run directly on console.
|
* NOTE: This example does not require any graphic device, it can run directly on console.
|
||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* mini_al.h - Audio device management lib (http://kcat.strangesoft.net/openal.html)
|
* mini_al.h - Audio device management lib (https://github.com/dr-soft/mini_al)
|
||||||
* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
|
* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/)
|
||||||
|
* dr_mp3.h - MP3 audio file loading (https://github.com/mackron/dr_libs)
|
||||||
|
* dr_flac.h - FLAC audio file loading (https://github.com/mackron/dr_libs)
|
||||||
* jar_xm.h - XM module file loading
|
* jar_xm.h - XM module file loading
|
||||||
* jar_mod.h - MOD audio file loading
|
* jar_mod.h - MOD audio file loading
|
||||||
* dr_flac.h - FLAC audio file loading
|
|
||||||
*
|
*
|
||||||
* COMPILATION:
|
* COMPILATION:
|
||||||
* gcc -c ..\..\src\external\mini_al.c -Wall -I.
|
* gcc -o raudio_standalone.exe raudio_standalone.c ..\..\src\raudio.c /
|
||||||
* gcc -o audio_standalone.exe audio_standalone.c ..\..\src\raudio.c mini_al.o /
|
* -I..\..\src -I..\..\src\external -L. -Wall -std=c99 -DRAUDIO_STANDALONE /
|
||||||
* -I..\..\src -I..\..\src\external -L. -Wall -std=c99 /
|
* -DSUPPORT_FILEFORMAT_WAV -DSUPPORT_FILEFORMAT_OGG -DSUPPORT_FILEFORMAT_MP3
|
||||||
* -DAUDIO_STANDALONE -DSUPPORT_FILEFORMAT_WAV -DSUPPORT_FILEFORMAT_OGG
|
|
||||||
*
|
*
|
||||||
* LICENSE: zlib/libpng
|
* LICENSE: zlib/libpng
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,12 @@ gcc -O2 -c textures.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
gcc -O2 -c text.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c text.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
gcc -O2 -c models.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c models.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
gcc -O2 -c raudio.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c raudio.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
gcc -O2 -c external/mini_al.c -Wall -I.
|
|
||||||
gcc -O2 -c utils.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
gcc -O2 -c utils.c -std=c99 -Wall -DPLATFORM_DESKTOP
|
||||||
|
|
||||||
:: .
|
:: .
|
||||||
:: . > Generate raylib library
|
:: . > Generate raylib library
|
||||||
:: ------------------------------
|
:: ------------------------------
|
||||||
ar rcs libraylib.a core.o rglfw.o shapes.o textures.o text.o models.o raudio.o mini_al.o utils.o
|
ar rcs libraylib.a core.o rglfw.o shapes.o textures.o text.o models.o raudio.o utils.o
|
||||||
:: .
|
:: .
|
||||||
:: > Installing raylib library
|
:: > Installing raylib library
|
||||||
:: -----------------------------
|
:: -----------------------------
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -232,9 +232,8 @@
|
||||||
<Text Include="ReadMe.txt" />
|
<Text Include="ReadMe.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\..\src\audio.c" />
|
<ClCompile Include="..\..\..\src\raudio.c" />
|
||||||
<ClCompile Include="..\..\..\src\core.c" />
|
<ClCompile Include="..\..\..\src\core.c" />
|
||||||
<ClCompile Include="..\..\..\src\external\mini_al.c" />
|
|
||||||
<ClCompile Include="..\..\..\src\models.c" />
|
<ClCompile Include="..\..\..\src\models.c" />
|
||||||
<ClCompile Include="..\..\..\src\rglfw.c" />
|
<ClCompile Include="..\..\..\src\rglfw.c" />
|
||||||
<ClCompile Include="..\..\..\src\shapes.c" />
|
<ClCompile Include="..\..\..\src\shapes.c" />
|
||||||
|
|
@ -247,6 +246,7 @@
|
||||||
<ClInclude Include="..\..\..\src\external\glad.h" />
|
<ClInclude Include="..\..\..\src\external\glad.h" />
|
||||||
<ClInclude Include="..\..\..\src\external\jar_mod.h" />
|
<ClInclude Include="..\..\..\src\external\jar_mod.h" />
|
||||||
<ClInclude Include="..\..\..\src\external\jar_xm.h" />
|
<ClInclude Include="..\..\..\src\external\jar_xm.h" />
|
||||||
|
<ClInclude Include="..\..\..\src\external\mini_al.h" />
|
||||||
<ClInclude Include="..\..\..\src\external\stb_image.h" />
|
<ClInclude Include="..\..\..\src\external\stb_image.h" />
|
||||||
<ClInclude Include="..\..\..\src\external\stb_image_resize.h" />
|
<ClInclude Include="..\..\..\src\external\stb_image_resize.h" />
|
||||||
<ClInclude Include="..\..\..\src\external\stb_image_write.h" />
|
<ClInclude Include="..\..\..\src\external\stb_image_write.h" />
|
||||||
|
|
|
||||||
|
|
@ -159,9 +159,8 @@
|
||||||
<Text Include="ReadMe.txt" />
|
<Text Include="ReadMe.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\..\src\audio.c" />
|
<ClCompile Include="..\..\..\src\raudio.c" />
|
||||||
<ClCompile Include="..\..\..\src\core.c" />
|
<ClCompile Include="..\..\..\src\core.c" />
|
||||||
<ClCompile Include="..\..\..\src\external\mini_al.c" />
|
|
||||||
<ClCompile Include="..\..\..\src\models.c" />
|
<ClCompile Include="..\..\..\src\models.c" />
|
||||||
<ClCompile Include="..\..\..\src\rglfw.c" />
|
<ClCompile Include="..\..\..\src\rglfw.c" />
|
||||||
<ClCompile Include="..\..\..\src\shapes.c" />
|
<ClCompile Include="..\..\..\src\shapes.c" />
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,10 @@ all of the flags.
|
||||||
#### Examples
|
#### Examples
|
||||||
| What the command does | Command |
|
| What the command does | Command |
|
||||||
|-------------------------------------------------------------|---------------------------|
|
|-------------------------------------------------------------|---------------------------|
|
||||||
| Build a release build, on Windows | `windows-build.bat` |
|
| Build a release build, on Windows | `build-windows.bat` |
|
||||||
| Build a release build, full recompile, on Linux | `./linux-build.sh -c` |
|
| Build a release build, full recompile, on Linux | `./build-linux.sh -c` |
|
||||||
| Build a debug build and run, on macOS | `./osx-build.sh -d -r` |
|
| Build a debug build and run, on macOS | `./build-osx.sh -d -r` |
|
||||||
| Build in debug, run, don't print at all, on Linux with `sh` | `sh linux-build.sh -drqq` |
|
| Build in debug, run, don't print at all, on Linux with `sh` | `sh build-linux.sh -drqq` |
|
||||||
|
|
||||||
|
|
||||||
[visual-studio]: https://visualstudio.microsoft.com/downloads/#visual-studio-community-2017
|
[visual-studio]: https://visualstudio.microsoft.com/downloads/#visual-studio-community-2017
|
||||||
|
|
|
||||||
158
projects/scripts/build-linux.sh
Normal file
158
projects/scripts/build-linux.sh
Normal file
|
|
@ -0,0 +1,158 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Change your executable name here
|
||||||
|
GAME_NAME="game"
|
||||||
|
|
||||||
|
# Set your sources here (relative to the ./builds/linux directory)
|
||||||
|
# Example with two source folders:
|
||||||
|
# SOURCES="../../src/*.c ../../src/submodule/*.c"
|
||||||
|
SOURCES="../../core_basic_window.c"
|
||||||
|
|
||||||
|
# Set your raylib/src location here, relative to the ./temp/x directory
|
||||||
|
RAYLIB_SRC="../../../../src"
|
||||||
|
|
||||||
|
# About this build script: it does many things, but in essence, it's
|
||||||
|
# very simple. It has 3 compiler invocations: building raylib (which
|
||||||
|
# is not done always, see logic by searching "Build raylib"), building
|
||||||
|
# src/*.c files, and linking together those two. Each invocation is
|
||||||
|
# wrapped in an if statement to make the -qq flag work, it's pretty
|
||||||
|
# verbose, sorry.
|
||||||
|
|
||||||
|
# Get arguments
|
||||||
|
while getopts ":hdurcq" opt; do
|
||||||
|
case $opt in
|
||||||
|
h)
|
||||||
|
echo "Usage: ./linux-build.sh [-hdurcqq]"
|
||||||
|
echo " -h Show this information"
|
||||||
|
echo " -d Faster builds that have debug symbols, and enable warnings"
|
||||||
|
echo " -u Run upx* on the executable after compilation (before -r)"
|
||||||
|
echo " -r Run the executable after compilation"
|
||||||
|
echo " -c Remove the temp/(debug|release) directory, ie. full recompile"
|
||||||
|
echo " -q Suppress this script's informational prints"
|
||||||
|
echo " -qq Suppress all prints, complete silence (> /dev/null 2>&1)"
|
||||||
|
echo ""
|
||||||
|
echo "* This is mostly here to make building simple \"shipping\" versions"
|
||||||
|
echo " easier, and it's a very small bit in the build scripts. The option"
|
||||||
|
echo " requires that you have upx installed and on your path, of course."
|
||||||
|
echo ""
|
||||||
|
echo "Examples:"
|
||||||
|
echo " Build a release build: ./linux-build.sh"
|
||||||
|
echo " Build a release build, full recompile: ./linux-build.sh -c"
|
||||||
|
echo " Build a debug build and run: ./linux-build.sh -d -r"
|
||||||
|
echo " Build in debug, run, don't print at all: ./linux-build.sh -drqq"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
d)
|
||||||
|
BUILD_DEBUG="1"
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
UPX_IT="1"
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
RUN_AFTER_BUILD="1"
|
||||||
|
;;
|
||||||
|
c)
|
||||||
|
BUILD_ALL="1"
|
||||||
|
;;
|
||||||
|
q)
|
||||||
|
if [ -n "$QUIET" ]; then
|
||||||
|
REALLY_QUIET="1"
|
||||||
|
else
|
||||||
|
QUIET="1"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
echo "Invalid option: -$OPTARG" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Set CC if it's not set already
|
||||||
|
if [ -z "$CC" ]; then
|
||||||
|
CC=cc
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Flags
|
||||||
|
OUTPUT_DIR="builds/linux"
|
||||||
|
COMPILATION_FLAGS="-std=c99 -Os -flto"
|
||||||
|
if [ "$CC" = "clang" ]; then
|
||||||
|
# Clang 7.0.1 fails to compile with -Os, possibly the same bug as this:
|
||||||
|
# https://www.mail-archive.com/llvm-bugs@lists.llvm.org/msg25771.html
|
||||||
|
COMPILATION_FLAGS="-std=c99 -O2 -flto"
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-WARNING: \$CC is clang, using -O2 instead of -Os."
|
||||||
|
fi
|
||||||
|
FINAL_COMPILE_FLAGS="-s"
|
||||||
|
WARNING_FLAGS="-Wall -Wextra -Wpedantic"
|
||||||
|
LINK_FLAGS="-lm -ldl -lpthread -lX11 -lxcb -lGL -lGLX -lXext -lGLdispatch -lXau -lXdmcp"
|
||||||
|
# Debug changes to flags
|
||||||
|
if [ -n "$BUILD_DEBUG" ]; then
|
||||||
|
OUTPUT_DIR="builds-debug/linux"
|
||||||
|
COMPILATION_FLAGS="-std=c99 -O0 -g"
|
||||||
|
FINAL_COMPILE_FLAGS=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Display what we're doing
|
||||||
|
if [ -n "$BUILD_DEBUG" ]; then
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling in debug mode. ($COMPILATION_FLAGS $WARNING_FLAGS)"
|
||||||
|
else
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling in release mode. ($COMPILATION_FLAGS $FINAL_COMPILE_FLAGS)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create the raylib cache directory
|
||||||
|
ROOT_DIR=$(pwd)
|
||||||
|
TEMP_DIR="temp/release"
|
||||||
|
if [ -n "$BUILD_DEBUG" ]; then
|
||||||
|
TEMP_DIR="temp/debug"
|
||||||
|
fi
|
||||||
|
# If there's a -c flag, remove the cache
|
||||||
|
if [ -d "$TEMP_DIR" ] && [ -n "$BUILD_ALL" ]; then
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Found cached raylib, rebuilding."
|
||||||
|
rm -r "$TEMP_DIR"
|
||||||
|
fi
|
||||||
|
# If temp directory doesn't exist, build raylib
|
||||||
|
if [ ! -d "$TEMP_DIR" ]; then
|
||||||
|
mkdir -p $TEMP_DIR
|
||||||
|
cd $TEMP_DIR
|
||||||
|
RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33"
|
||||||
|
RAYLIB_C_FILES="$RAYLIB_SRC/core.c $RAYLIB_SRC/shapes.c $RAYLIB_SRC/textures.c $RAYLIB_SRC/text.c $RAYLIB_SRC/models.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c $RAYLIB_SRC/rglfw.c"
|
||||||
|
RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I$RAYLIB_SRC/external/glfw/include"
|
||||||
|
|
||||||
|
if [ -n "$REALLY_QUIET" ]; then
|
||||||
|
$CC -c $RAYLIB_DEFINES $RAYLIB_INCLUDE_FLAGS $COMPILATION_FLAGS $RAYLIB_C_FILES > /dev/null 2>&1
|
||||||
|
else
|
||||||
|
$CC -c $RAYLIB_DEFINES $RAYLIB_INCLUDE_FLAGS $COMPILATION_FLAGS $RAYLIB_C_FILES
|
||||||
|
fi
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Raylib compiled into object files in: $TEMP_DIR/"
|
||||||
|
cd $ROOT_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build the actual game
|
||||||
|
mkdir -p $OUTPUT_DIR
|
||||||
|
cd $OUTPUT_DIR
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling game code."
|
||||||
|
if [ -n "$REALLY_QUIET" ]; then
|
||||||
|
$CC -c -o main.o -I$RAYLIB_SRC $COMPILATION_FLAGS $WARNING_FLAGS $SOURCES > /dev/null 2>&1
|
||||||
|
$CC -o $GAME_NAME $ROOT_DIR/$TEMP_DIR/*.o main.o $LINK_FLAGS > /dev/null 2>&1
|
||||||
|
else
|
||||||
|
$CC -c -o main.o -I$RAYLIB_SRC $COMPILATION_FLAGS $WARNING_FLAGS $SOURCES
|
||||||
|
$CC -o $GAME_NAME $ROOT_DIR/$TEMP_DIR/*.o main.o $LINK_FLAGS
|
||||||
|
fi
|
||||||
|
rm main.o
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Game compiled into an executable in: $OUTPUT_DIR/"
|
||||||
|
|
||||||
|
if [ -n "$UPX_IT" ]; then
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Packing $GAME_NAME with upx."
|
||||||
|
upx $GAME_NAME > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$RUN_AFTER_BUILD" ]; then
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Running."
|
||||||
|
if [ -n "$REALLY_QUIET" ]; then
|
||||||
|
./$GAME_NAME > /dev/null 2>&1
|
||||||
|
else
|
||||||
|
./$GAME_NAME
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
cd $ROOT_DIR
|
||||||
|
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: All done."
|
||||||
154
projects/scripts/build-osx.sh
Normal file
154
projects/scripts/build-osx.sh
Normal file
|
|
@ -0,0 +1,154 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Change your executable name here
|
||||||
|
GAME_NAME="game"
|
||||||
|
|
||||||
|
# Set your sources here (relative to the ./builds/osx directory)
|
||||||
|
# Example with two source folders:
|
||||||
|
# SOURCES="../../src/*.c ../../src/submodule/*.c"
|
||||||
|
SOURCES="../../core_basic_window.c"
|
||||||
|
|
||||||
|
# Set your raylib/src location here, relative to the ./temp/x directory
|
||||||
|
RAYLIB_SRC="../../../../src"
|
||||||
|
|
||||||
|
# About this build script: it does many things, but in essence, it's
|
||||||
|
# very simple. It has 3 compiler invocations: building raylib (which
|
||||||
|
# is not done always, see logic by searching "Build raylib"), building
|
||||||
|
# src/*.c files, and linking together those two. Each invocation is
|
||||||
|
# wrapped in an if statement to make the -qq flag work, it's pretty
|
||||||
|
# verbose, sorry.
|
||||||
|
|
||||||
|
# Get arguments
|
||||||
|
while getopts ":hdurcq" opt; do
|
||||||
|
case $opt in
|
||||||
|
h)
|
||||||
|
echo "Usage: ./osx-build.sh [-hdurcqq]"
|
||||||
|
echo " -h Show this information"
|
||||||
|
echo " -d Faster builds that have debug symbols, and enable warnings"
|
||||||
|
echo " -u Run upx* on the executable after compilation (before -r)"
|
||||||
|
echo " -r Run the executable after compilation"
|
||||||
|
echo " -c Remove the temp/(debug|release) directory, ie. full recompile"
|
||||||
|
echo " -q Suppress this script's informational prints"
|
||||||
|
echo " -qq Suppress all prints, complete silence (> /dev/null 2>&1)"
|
||||||
|
echo ""
|
||||||
|
echo "* This is mostly here to make building simple \"shipping\" versions"
|
||||||
|
echo " easier, and it's a very small bit in the build scripts. The option"
|
||||||
|
echo " requires that you have upx installed and on your path, of course."
|
||||||
|
echo ""
|
||||||
|
echo "Examples:"
|
||||||
|
echo " Build a release build: ./osx-build.sh"
|
||||||
|
echo " Build a release build, full recompile: ./osx-build.sh -c"
|
||||||
|
echo " Build a debug build and run: ./osx-build.sh -d -r"
|
||||||
|
echo " Build in debug, run, don't print at all: ./osx-build.sh -drqq"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
d)
|
||||||
|
BUILD_DEBUG="1"
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
UPX_IT="1"
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
RUN_AFTER_BUILD="1"
|
||||||
|
;;
|
||||||
|
c)
|
||||||
|
BUILD_ALL="1"
|
||||||
|
;;
|
||||||
|
q)
|
||||||
|
if [ -n "$QUIET" ]; then
|
||||||
|
REALLY_QUIET="1"
|
||||||
|
else
|
||||||
|
QUIET="1"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
echo "Invalid option: -$OPTARG" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Set CC if it's not set already
|
||||||
|
if [ -z "$CC" ]; then
|
||||||
|
CC=cc
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Flags
|
||||||
|
OUTPUT_DIR="builds/osx"
|
||||||
|
COMPILATION_FLAGS="-std=c99 -O2 -flto"
|
||||||
|
FINAL_COMPILE_FLAGS="-s"
|
||||||
|
WARNING_FLAGS="-Wall -Wextra -Wpedantic"
|
||||||
|
LINK_FLAGS="-framework OpenGL -framework OpenAL -framework IOKit -framework CoreVideo -framework Cocoa"
|
||||||
|
# Debug changes to flags
|
||||||
|
if [ -n "$BUILD_DEBUG" ]; then
|
||||||
|
OUTPUT_DIR="builds-debug/osx"
|
||||||
|
COMPILATION_FLAGS="-std=c99 -O0 -g"
|
||||||
|
FINAL_COMPILE_FLAGS=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Display what we're doing
|
||||||
|
if [ -n "$BUILD_DEBUG" ]; then
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling in debug mode. ($COMPILATION_FLAGS $WARNING_FLAGS)"
|
||||||
|
else
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling in release mode. ($COMPILATION_FLAGS $FINAL_COMPILE_FLAGS)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create the raylib cache directory
|
||||||
|
ROOT_DIR=$(pwd)
|
||||||
|
TEMP_DIR="temp/release"
|
||||||
|
if [ -n "$BUILD_DEBUG" ]; then
|
||||||
|
TEMP_DIR="temp/debug"
|
||||||
|
fi
|
||||||
|
# If there's a -c flag, remove the cache
|
||||||
|
if [ -d "$TEMP_DIR" ] && [ -n "$BUILD_ALL" ]; then
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Found cached raylib, rebuilding."
|
||||||
|
rm -r "$TEMP_DIR"
|
||||||
|
fi
|
||||||
|
# If temp directory doesn't exist, build raylib
|
||||||
|
if [ ! -d "$TEMP_DIR" ]; then
|
||||||
|
mkdir -p $TEMP_DIR
|
||||||
|
cd $TEMP_DIR
|
||||||
|
RAYLIB_DEFINES="-D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_33"
|
||||||
|
RAYLIB_C_FILES="$RAYLIB_SRC/core.c $RAYLIB_SRC/shapes.c $RAYLIB_SRC/textures.c $RAYLIB_SRC/text.c $RAYLIB_SRC/models.c $RAYLIB_SRC/utils.c $RAYLIB_SRC/raudio.c"
|
||||||
|
RAYLIB_INCLUDE_FLAGS="-I$RAYLIB_SRC -I$RAYLIB_SRC/external/glfw/include"
|
||||||
|
|
||||||
|
if [ -n "$REALLY_QUIET" ]; then
|
||||||
|
$CC -c $RAYLIB_DEFINES $RAYLIB_INCLUDE_FLAGS $COMPILATION_FLAGS -x objective-c $RAYLIB_SRC/rglfw.c > /dev/null 2>&1
|
||||||
|
$CC -c $RAYLIB_DEFINES $RAYLIB_INCLUDE_FLAGS $COMPILATION_FLAGS $RAYLIB_C_FILES > /dev/null 2>&1
|
||||||
|
else
|
||||||
|
$CC -c $RAYLIB_DEFINES $RAYLIB_INCLUDE_FLAGS $COMPILATION_FLAGS -x objective-c $RAYLIB_SRC/rglfw.c
|
||||||
|
$CC -c $RAYLIB_DEFINES $RAYLIB_INCLUDE_FLAGS $COMPILATION_FLAGS $RAYLIB_C_FILES
|
||||||
|
fi
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Raylib compiled into object files in: $TEMP_DIR/"
|
||||||
|
cd $ROOT_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build the actual game
|
||||||
|
mkdir -p $OUTPUT_DIR
|
||||||
|
cd $OUTPUT_DIR
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Compiling game code."
|
||||||
|
if [ -n "$REALLY_QUIET" ]; then
|
||||||
|
$CC -c -o main.o -I$RAYLIB_SRC $COMPILATION_FLAGS $WARNING_FLAGS $SOURCES > /dev/null 2>&1
|
||||||
|
$CC -o $GAME_NAME $ROOT_DIR/$TEMP_DIR/*.o main.o $LINK_FLAGS > /dev/null 2>&1
|
||||||
|
else
|
||||||
|
$CC -c -o main.o -I$RAYLIB_SRC $COMPILATION_FLAGS $WARNING_FLAGS $SOURCES
|
||||||
|
$CC -o $GAME_NAME $ROOT_DIR/$TEMP_DIR/*.o main.o $LINK_FLAGS
|
||||||
|
fi
|
||||||
|
rm main.o
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Game compiled into an executable in: $OUTPUT_DIR/"
|
||||||
|
|
||||||
|
if [ -n "$UPX_IT" ]; then
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Packing $GAME_NAME with upx."
|
||||||
|
upx $GAME_NAME > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$RUN_AFTER_BUILD" ]; then
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: Running."
|
||||||
|
if [ -n "$REALLY_QUIET" ]; then
|
||||||
|
./$GAME_NAME > /dev/null 2>&1
|
||||||
|
else
|
||||||
|
./$GAME_NAME
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
cd $ROOT_DIR
|
||||||
|
|
||||||
|
[ -z "$QUIET" ] && echo "COMPILE-INFO: All done."
|
||||||
211
projects/scripts/build-windows.bat
Normal file
211
projects/scripts/build-windows.bat
Normal file
|
|
@ -0,0 +1,211 @@
|
||||||
|
@echo off
|
||||||
|
REM Change your executable name here
|
||||||
|
set GAME_NAME=game.exe
|
||||||
|
|
||||||
|
REM Set your sources here (relative to the builds\windows directory)
|
||||||
|
REM Example with two source folders:
|
||||||
|
REM set SOURCES=..\..\src\*.c ..\..\src\submodule\*.c
|
||||||
|
set SOURCES=..\..\core_basic_window.c
|
||||||
|
|
||||||
|
REM Set your raylib/src location here, relative to the ./temp/x directory
|
||||||
|
set RAYLIB_SRC=..\..\..\..\src
|
||||||
|
|
||||||
|
REM About this build script: it does many things, but in essence, it's
|
||||||
|
REM very simple. It has 3 compiler invocations: building raylib (which
|
||||||
|
REM is not done always, see logic by searching "Build raylib"), building
|
||||||
|
REM src/*.c files, and linking together those two. Each invocation is
|
||||||
|
REM wrapped in an if statement to make the -qq flag work, it's pretty
|
||||||
|
REM verbose, sorry.
|
||||||
|
|
||||||
|
REM To skip to the actual building part of the script, search for ":BUILD"
|
||||||
|
|
||||||
|
REM For the ! variable notation
|
||||||
|
setlocal EnableDelayedExpansion
|
||||||
|
REM For shifting, which the command line argument parsing needs
|
||||||
|
setlocal EnableExtensions
|
||||||
|
|
||||||
|
|
||||||
|
:ARG_LOOP
|
||||||
|
set ARG=%1
|
||||||
|
if "!ARG!" == "" ( goto PREPARE )
|
||||||
|
IF NOT "x!ARG!" == "x!ARG:h=!" (
|
||||||
|
goto HELP
|
||||||
|
)
|
||||||
|
IF NOT "x!ARG!" == "x!ARG:d=!" (
|
||||||
|
set BUILD_DEBUG=1
|
||||||
|
)
|
||||||
|
IF NOT "x!ARG!" == "x!ARG:u=!" (
|
||||||
|
set UPX_IT=1
|
||||||
|
)
|
||||||
|
IF NOT "x!ARG!" == "x!ARG:r=!" (
|
||||||
|
set RUN_AFTER_BUILD=1
|
||||||
|
)
|
||||||
|
IF NOT "x!ARG!" == "x!ARG:c=!" (
|
||||||
|
set BUILD_ALL=1
|
||||||
|
)
|
||||||
|
IF NOT "x!ARG!" == "x!ARG:qq=!" (
|
||||||
|
set QUIET=1
|
||||||
|
set REALLY_QUIET=1
|
||||||
|
) ELSE IF NOT "x!ARG!" == "x!ARG:q=!" (
|
||||||
|
IF DEFINED QUIET (
|
||||||
|
set REALLY_QUIET=1
|
||||||
|
) ELSE (
|
||||||
|
set QUIET=1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
IF NOT "x!ARG!" == "x!ARG:v=!" (
|
||||||
|
set VERBOSE=1
|
||||||
|
)
|
||||||
|
IF NOT "%1" == "" (
|
||||||
|
shift /1
|
||||||
|
goto ARG_LOOP
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
:HELP
|
||||||
|
echo Usage: windows-build.bat [-hdurcqqv]
|
||||||
|
echo -h Show this information
|
||||||
|
echo -d Faster builds that have debug symbols, and enable warnings
|
||||||
|
echo -u Run upx* on the executable after compilation (before -r)
|
||||||
|
echo -r Run the executable after compilation
|
||||||
|
echo -c Remove the temp\{debug,release} directory, ie. full recompile
|
||||||
|
echo -q Suppress this script's informational prints
|
||||||
|
echo -qq Suppress all prints, complete silence
|
||||||
|
echo -v cl.exe normally prints out a lot of superficial information, as
|
||||||
|
echo well as the MSVC build environment activation scripts, but these are
|
||||||
|
echo mostly suppressed by default. If you do want to see everything, use
|
||||||
|
echo this flag.
|
||||||
|
echo.
|
||||||
|
echo * This is mostly here to make building simple "shipping" versions
|
||||||
|
echo easier, and it's a very small bit in the build scripts. The option
|
||||||
|
echo requires that you have upx installed and on your path, of course.
|
||||||
|
echo.
|
||||||
|
echo Examples:
|
||||||
|
echo Build a release build: windows-build.bat
|
||||||
|
echo Build a release build, full recompile: windows-build.bat -c
|
||||||
|
echo Build a debug build and run: windows-build.bat -d -r
|
||||||
|
echo Build in debug, run, don't print at all: windows-build.bat -drqq
|
||||||
|
exit /B
|
||||||
|
|
||||||
|
|
||||||
|
:PREPARE
|
||||||
|
REM Activate the msvc build environment
|
||||||
|
IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" (
|
||||||
|
set VC_INIT="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
|
||||||
|
) ELSE IF EXIST "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" (
|
||||||
|
set VC_INIT="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat"
|
||||||
|
) ELSE IF EXIST "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" (
|
||||||
|
set VC_INIT="C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat"
|
||||||
|
) ELSE (
|
||||||
|
REM Initialize your vc environment here if the defaults don't work
|
||||||
|
REM set VC_INIT="C:\your\path\here\vcvarsall.bat"
|
||||||
|
REM And then remove/comment out the following two lines
|
||||||
|
echo "Couldn't find vcvarsall.bat or vcbuildtools.bat, please set it manually."
|
||||||
|
exit /B
|
||||||
|
)
|
||||||
|
IF DEFINED VERBOSE (
|
||||||
|
call !VC_INIT! x86
|
||||||
|
) ELSE (
|
||||||
|
call !VC_INIT! x86 > NUL 2>&1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
:BUILD
|
||||||
|
REM Flags
|
||||||
|
set OUTPUT_FLAG=/Fe: "!GAME_NAME!"
|
||||||
|
set COMPILATION_FLAGS=/O1 /GL
|
||||||
|
set WARNING_FLAGS=
|
||||||
|
set SUBSYSTEM_FLAGS=/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup
|
||||||
|
set LINK_FLAGS=/link /LTCG kernel32.lib user32.lib shell32.lib winmm.lib gdi32.lib opengl32.lib
|
||||||
|
set OUTPUT_DIR=builds\windows
|
||||||
|
REM Debug changes to flags
|
||||||
|
IF DEFINED BUILD_DEBUG (
|
||||||
|
set OUTPUT_FLAG=/Fe: "!GAME_NAME!"
|
||||||
|
set COMPILATION_FLAGS=/Od /Zi
|
||||||
|
set WARNING_FLAGS=/Wall
|
||||||
|
set SUBSYSTEM_FLAGS=
|
||||||
|
set LINK_FLAGS=/link kernel32.lib user32.lib shell32.lib winmm.lib gdi32.lib opengl32.lib
|
||||||
|
set OUTPUT_DIR=builds-debug\windows
|
||||||
|
)
|
||||||
|
IF NOT DEFINED VERBOSE (
|
||||||
|
set VERBOSITY_FLAG=/nologo
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Display what we're doing
|
||||||
|
IF DEFINED BUILD_DEBUG (
|
||||||
|
IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling in debug mode, flags: !COMPILATION_FLAGS! !WARNING_FLAGS!
|
||||||
|
) ELSE (
|
||||||
|
IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling in release mode, flags: !COMPILATION_FLAGS! /link /LTCG
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Create the temp directory for raylib
|
||||||
|
set "ROOT_DIR=%CD%"
|
||||||
|
set "TEMP_DIR=temp\release"
|
||||||
|
IF DEFINED BUILD_DEBUG (
|
||||||
|
set "TEMP_DIR=temp\debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
IF DEFINED BUILD_ALL (
|
||||||
|
IF EXIST !TEMP_DIR!\ (
|
||||||
|
IF NOT DEFINED QUIET echo COMPILE-INFO: Found cached raylib, rebuilding.
|
||||||
|
del /Q !TEMP_DIR!
|
||||||
|
rmdir !TEMP_DIR!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Build raylib if it hasn't been cached in TEMP_DIR
|
||||||
|
IF NOT EXIST !TEMP_DIR!\ (
|
||||||
|
mkdir !TEMP_DIR!
|
||||||
|
cd !TEMP_DIR!
|
||||||
|
REM Raylib's src folder
|
||||||
|
set "RAYLIB_DEFINES=/D_DEFAULT_SOURCE /DPLATFORM_DESKTOP /DGRAPHICS_API_OPENGL_33"
|
||||||
|
set RAYLIB_C_FILES="!RAYLIB_SRC!\core.c" "!RAYLIB_SRC!\shapes.c" "!RAYLIB_SRC!\textures.c" "!RAYLIB_SRC!\text.c" "!RAYLIB_SRC!\models.c" "!RAYLIB_SRC!\utils.c" "!RAYLIB_SRC!\raudio.c" "!RAYLIB_SRC!\rglfw.c"
|
||||||
|
set RAYLIB_INCLUDE_FLAGS=/I"!RAYLIB_SRC!" /I"!RAYLIB_SRC!\external\glfw\include"
|
||||||
|
|
||||||
|
IF DEFINED REALLY_QUIET (
|
||||||
|
cl.exe /w /c !RAYLIB_DEFINES! !RAYLIB_INCLUDE_FLAGS! !COMPILATION_FLAGS! !RAYLIB_C_FILES! > NUL 2>&1
|
||||||
|
) ELSE (
|
||||||
|
cl.exe /w /c !VERBOSITY_FLAG! !RAYLIB_DEFINES! !RAYLIB_INCLUDE_FLAGS! !COMPILATION_FLAGS! !RAYLIB_C_FILES!
|
||||||
|
)
|
||||||
|
IF NOT DEFINED QUIET echo COMPILE-INFO: Raylib compiled into object files in: !TEMP_DIR!\
|
||||||
|
|
||||||
|
REM Out of the temp directory
|
||||||
|
cd !ROOT_DIR!
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Move to the build directory
|
||||||
|
IF NOT EXIST !OUTPUT_DIR! mkdir !OUTPUT_DIR!
|
||||||
|
cd !OUTPUT_DIR!
|
||||||
|
|
||||||
|
REM Build the actual game
|
||||||
|
IF NOT DEFINED QUIET echo COMPILE-INFO: Compiling game code.
|
||||||
|
IF DEFINED REALLY_QUIET (
|
||||||
|
cl.exe !VERBOSITY_FLAG! /Fo"main.obj" !COMPILATION_FLAGS! !WARNING_FLAGS! /c /I"!RAYLIB_SRC!" !SOURCES! > NUL 2>&1
|
||||||
|
cl.exe !VERBOSITY_FLAG! !OUTPUT_FLAG! "!ROOT_DIR!\!TEMP_DIR!\*.obj" main.obj !LINK_FLAGS! !SUBSYSTEM_FLAGS! > NUL 2>&1
|
||||||
|
) ELSE (
|
||||||
|
cl.exe !VERBOSITY_FLAG! /Fo"main.obj" !COMPILATION_FLAGS! !WARNING_FLAGS! /c /I"!RAYLIB_SRC!" !SOURCES!
|
||||||
|
cl.exe !VERBOSITY_FLAG! !OUTPUT_FLAG! "!ROOT_DIR!\!TEMP_DIR!\*.obj" main.obj !LINK_FLAGS! !SUBSYSTEM_FLAGS!
|
||||||
|
)
|
||||||
|
del main.obj
|
||||||
|
IF NOT DEFINED QUIET echo COMPILE-INFO: Game compiled into an executable in: !OUTPUT_DIR!\
|
||||||
|
|
||||||
|
REM Run upx
|
||||||
|
IF DEFINED UPX_IT (
|
||||||
|
IF NOT DEFINED QUIET echo COMPILE-INFO: Packing !GAME_NAME! with upx.
|
||||||
|
upx !GAME_NAME! > NUL 2>&1
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Finally, run the produced executable
|
||||||
|
IF DEFINED RUN_AFTER_BUILD (
|
||||||
|
IF NOT DEFINED QUIET echo COMPILE-INFO: Running.
|
||||||
|
IF DEFINED REALLY_QUIET (
|
||||||
|
!GAME_NAME! > NUL 2>&1
|
||||||
|
) ELSE (
|
||||||
|
!GAME_NAME!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Back to development directory
|
||||||
|
cd !ROOT_DIR!
|
||||||
|
|
||||||
|
IF NOT DEFINED QUIET echo COMPILE-INFO: All done.
|
||||||
|
|
@ -45,9 +45,8 @@ endif()
|
||||||
add_definitions("-DRAYLIB_CMAKE=1")
|
add_definitions("-DRAYLIB_CMAKE=1")
|
||||||
|
|
||||||
if(USE_AUDIO)
|
if(USE_AUDIO)
|
||||||
file(GLOB mini_al external/mini_al.c)
|
|
||||||
MESSAGE(STATUS "Audio Backend: mini_al")
|
MESSAGE(STATUS "Audio Backend: mini_al")
|
||||||
set(sources ${raylib_sources} ${mini_al})
|
set(sources ${raylib_sources})
|
||||||
else()
|
else()
|
||||||
MESSAGE(STATUS "Audio Backend: None (-DUSE_AUDIO=OFF)")
|
MESSAGE(STATUS "Audio Backend: None (-DUSE_AUDIO=OFF)")
|
||||||
set(INCLUDE_AUDIO_MODULE 0)
|
set(INCLUDE_AUDIO_MODULE 0)
|
||||||
|
|
|
||||||
|
|
@ -404,7 +404,6 @@ endif
|
||||||
|
|
||||||
ifeq ($(INCLUDE_AUDIO_MODULE),TRUE)
|
ifeq ($(INCLUDE_AUDIO_MODULE),TRUE)
|
||||||
OBJS += raudio.o
|
OBJS += raudio.o
|
||||||
OBJS += mini_al.o
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
||||||
|
|
@ -532,10 +531,6 @@ models.o : models.c raylib.h rlgl.h raymath.h
|
||||||
raudio.o : raudio.c raylib.h
|
raudio.o : raudio.c raylib.h
|
||||||
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
|
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
|
||||||
|
|
||||||
# Compile mini_al audio library
|
|
||||||
mini_al.o : external/mini_al.c external/mini_al.h
|
|
||||||
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
|
|
||||||
|
|
||||||
# Compile utils module
|
# Compile utils module
|
||||||
utils.o : utils.c utils.h
|
utils.o : utils.c utils.h
|
||||||
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
|
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
|
||||||
|
|
|
||||||
17
src/core.c
17
src/core.c
|
|
@ -984,6 +984,23 @@ const char *GetMonitorName(int monitor)
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get clipboard text content
|
||||||
|
// NOTE: returned string is allocated and freed by GLFW
|
||||||
|
const char *GetClipboardText(void)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
return glfwGetClipboardString(window);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set clipboard text content
|
||||||
|
void SetClipboardText(const char *text)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
glfwSetClipboardString(window, text);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Show mouse cursor
|
// Show mouse cursor
|
||||||
void ShowCursor(void)
|
void ShowCursor(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
3749
src/external/cgltf.h
vendored
3749
src/external/cgltf.h
vendored
File diff suppressed because it is too large
Load diff
8
src/external/mini_al.c
vendored
8
src/external/mini_al.c
vendored
|
|
@ -1,8 +0,0 @@
|
||||||
// The implementation of mini_al needs to #include windows.h which means it needs to go into
|
|
||||||
// it's own translation unit. Not doing this will cause conflicts with CloseWindow(), etc.
|
|
||||||
#define MINI_AL_IMPLEMENTATION
|
|
||||||
#define MAL_NO_JACK
|
|
||||||
#define MAL_NO_OPENAL
|
|
||||||
#define MAL_NO_SDL
|
|
||||||
//#define MAL_NO_NULL
|
|
||||||
#include "mini_al.h"
|
|
||||||
72
src/external/mini_al.h
vendored
72
src/external/mini_al.h
vendored
|
|
@ -2775,7 +2775,79 @@ mal_uint64 mal_sine_wave_read_ex(mal_sine_wave* pSineWave, mal_uint64 frameCount
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MAL_WIN32
|
#ifdef MAL_WIN32
|
||||||
|
|
||||||
|
// @raysan5: To avoid conflicting windows.h symbols with raylib, so flags are defined
|
||||||
|
// WARNING: Those flags avoid inclusion of some Win32 headers that could be required
|
||||||
|
// by user at some point and won't be included...
|
||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// If defined, the following flags inhibit definition of the indicated items.
|
||||||
|
#define NOGDICAPMASKS // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
|
||||||
|
#define NOVIRTUALKEYCODES // VK_*
|
||||||
|
#define NOWINMESSAGES // WM_*, EM_*, LB_*, CB_*
|
||||||
|
#define NOWINSTYLES // WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_*
|
||||||
|
#define NOSYSMETRICS // SM_*
|
||||||
|
#define NOMENUS // MF_*
|
||||||
|
#define NOICONS // IDI_*
|
||||||
|
#define NOKEYSTATES // MK_*
|
||||||
|
#define NOSYSCOMMANDS // SC_*
|
||||||
|
#define NORASTEROPS // Binary and Tertiary raster ops
|
||||||
|
#define NOSHOWWINDOW // SW_*
|
||||||
|
#define OEMRESOURCE // OEM Resource values
|
||||||
|
#define NOATOM // Atom Manager routines
|
||||||
|
#define NOCLIPBOARD // Clipboard routines
|
||||||
|
#define NOCOLOR // Screen colors
|
||||||
|
#define NOCTLMGR // Control and Dialog routines
|
||||||
|
#define NODRAWTEXT // DrawText() and DT_*
|
||||||
|
#define NOGDI // All GDI defines and routines
|
||||||
|
#define NOKERNEL // All KERNEL defines and routines
|
||||||
|
#define NOUSER // All USER defines and routines
|
||||||
|
//#define NONLS // All NLS defines and routines
|
||||||
|
#define NOMB // MB_* and MessageBox()
|
||||||
|
#define NOMEMMGR // GMEM_*, LMEM_*, GHND, LHND, associated routines
|
||||||
|
#define NOMETAFILE // typedef METAFILEPICT
|
||||||
|
#define NOMINMAX // Macros min(a,b) and max(a,b)
|
||||||
|
#define NOMSG // typedef MSG and associated routines
|
||||||
|
#define NOOPENFILE // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
|
||||||
|
#define NOSCROLL // SB_* and scrolling routines
|
||||||
|
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
|
||||||
|
#define NOSOUND // Sound driver routines
|
||||||
|
#define NOTEXTMETRIC // typedef TEXTMETRIC and associated routines
|
||||||
|
#define NOWH // SetWindowsHook and WH_*
|
||||||
|
#define NOWINOFFSETS // GWL_*, GCL_*, associated routines
|
||||||
|
#define NOCOMM // COMM driver routines
|
||||||
|
#define NOKANJI // Kanji support stuff.
|
||||||
|
#define NOHELP // Help engine interface.
|
||||||
|
#define NOPROFILER // Profiler interface.
|
||||||
|
#define NODEFERWINDOWPOS // DeferWindowPos routines
|
||||||
|
#define NOMCX // Modem Configuration Extensions
|
||||||
|
|
||||||
|
// Type required before windows.h inclusion
|
||||||
|
typedef struct tagMSG *LPMSG;
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
// Type required by some unused function...
|
||||||
|
typedef struct tagBITMAPINFOHEADER {
|
||||||
|
DWORD biSize;
|
||||||
|
LONG biWidth;
|
||||||
|
LONG biHeight;
|
||||||
|
WORD biPlanes;
|
||||||
|
WORD biBitCount;
|
||||||
|
DWORD biCompression;
|
||||||
|
DWORD biSizeImage;
|
||||||
|
LONG biXPelsPerMeter;
|
||||||
|
LONG biYPelsPerMeter;
|
||||||
|
DWORD biClrUsed;
|
||||||
|
DWORD biClrImportant;
|
||||||
|
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;
|
||||||
|
|
||||||
|
// @raysan5: Some required types defined for MSVC/TinyC compiler
|
||||||
|
#if defined(_MSC_VER) || defined(__TINYC__)
|
||||||
|
#include "propidl.h"
|
||||||
|
#endif
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <stdlib.h> // For malloc()/free()
|
#include <stdlib.h> // For malloc()/free()
|
||||||
#include <string.h> // For memset()
|
#include <string.h> // For memset()
|
||||||
|
|
|
||||||
153
src/external/stb_image.h
vendored
153
src/external/stb_image.h
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
/* stb_image - v2.19 - public domain image loader - http://nothings.org/stb
|
/* stb_image - v2.20 - public domain image loader - http://nothings.org/stb
|
||||||
no warranty implied; use at your own risk
|
no warranty implied; use at your own risk
|
||||||
|
|
||||||
Do this:
|
Do this:
|
||||||
|
|
@ -48,6 +48,7 @@ LICENSE
|
||||||
|
|
||||||
RECENT REVISION HISTORY:
|
RECENT REVISION HISTORY:
|
||||||
|
|
||||||
|
2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs
|
||||||
2.19 (2018-02-11) fix warning
|
2.19 (2018-02-11) fix warning
|
||||||
2.18 (2018-01-30) fix warnings
|
2.18 (2018-01-30) fix warnings
|
||||||
2.17 (2018-01-29) bugfix, 1-bit BMP, 16-bitness query, fix warnings
|
2.17 (2018-01-29) bugfix, 1-bit BMP, 16-bitness query, fix warnings
|
||||||
|
|
@ -84,6 +85,7 @@ RECENT REVISION HISTORY:
|
||||||
Fabian "ryg" Giesen Anael Seghezzi (is-16-bit query)
|
Fabian "ryg" Giesen Anael Seghezzi (is-16-bit query)
|
||||||
Arseny Kapoulkine
|
Arseny Kapoulkine
|
||||||
John-Mark Allen
|
John-Mark Allen
|
||||||
|
Carmelo J Fdez-Aguera
|
||||||
|
|
||||||
Bug & warning fixes
|
Bug & warning fixes
|
||||||
Marc LeBlanc David Woo Guillaume George Martins Mozeiko
|
Marc LeBlanc David Woo Guillaume George Martins Mozeiko
|
||||||
|
|
@ -99,7 +101,7 @@ RECENT REVISION HISTORY:
|
||||||
Aldo Culquicondor Philipp Wiesemann Dale Weiler github:sammyhw
|
Aldo Culquicondor Philipp Wiesemann Dale Weiler github:sammyhw
|
||||||
Oriol Ferrer Mesia Josh Tobin Matthew Gregan github:phprus
|
Oriol Ferrer Mesia Josh Tobin Matthew Gregan github:phprus
|
||||||
Julian Raschke Gregory Mullen Baldur Karlsson github:poppolopoppo
|
Julian Raschke Gregory Mullen Baldur Karlsson github:poppolopoppo
|
||||||
Christian Floisand Kevin Schmidt github:darealshinji
|
Christian Floisand Kevin Schmidt JR Smith github:darealshinji
|
||||||
Blazej Dariusz Roszkowski github:Michaelangel007
|
Blazej Dariusz Roszkowski github:Michaelangel007
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -161,6 +163,16 @@ RECENT REVISION HISTORY:
|
||||||
//
|
//
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
//
|
//
|
||||||
|
// UNICODE:
|
||||||
|
//
|
||||||
|
// If compiling for Windows and you wish to use Unicode filenames, compile
|
||||||
|
// with
|
||||||
|
// #define STBI_WINDOWS_UTF8
|
||||||
|
// and pass utf8-encoded filenames. Call stbiw_convert_wchar_to_utf8 to convert
|
||||||
|
// Windows wchar_t filenames to utf8.
|
||||||
|
//
|
||||||
|
// ===========================================================================
|
||||||
|
//
|
||||||
// Philosophy
|
// Philosophy
|
||||||
//
|
//
|
||||||
// stb libraries are designed with the following priorities:
|
// stb libraries are designed with the following priorities:
|
||||||
|
|
@ -171,12 +183,12 @@ RECENT REVISION HISTORY:
|
||||||
//
|
//
|
||||||
// Sometimes I let "good performance" creep up in priority over "easy to maintain",
|
// Sometimes I let "good performance" creep up in priority over "easy to maintain",
|
||||||
// and for best performance I may provide less-easy-to-use APIs that give higher
|
// and for best performance I may provide less-easy-to-use APIs that give higher
|
||||||
// performance, in addition to the easy to use ones. Nevertheless, it's important
|
// performance, in addition to the easy-to-use ones. Nevertheless, it's important
|
||||||
// to keep in mind that from the standpoint of you, a client of this library,
|
// to keep in mind that from the standpoint of you, a client of this library,
|
||||||
// all you care about is #1 and #3, and stb libraries DO NOT emphasize #3 above all.
|
// all you care about is #1 and #3, and stb libraries DO NOT emphasize #3 above all.
|
||||||
//
|
//
|
||||||
// Some secondary priorities arise directly from the first two, some of which
|
// Some secondary priorities arise directly from the first two, some of which
|
||||||
// make more explicit reasons why performance can't be emphasized.
|
// provide more explicit reasons why performance can't be emphasized.
|
||||||
//
|
//
|
||||||
// - Portable ("ease of use")
|
// - Portable ("ease of use")
|
||||||
// - Small source code footprint ("easy to maintain")
|
// - Small source code footprint ("easy to maintain")
|
||||||
|
|
@ -219,11 +231,10 @@ RECENT REVISION HISTORY:
|
||||||
//
|
//
|
||||||
// HDR image support (disable by defining STBI_NO_HDR)
|
// HDR image support (disable by defining STBI_NO_HDR)
|
||||||
//
|
//
|
||||||
// stb_image now supports loading HDR images in general, and currently
|
// stb_image supports loading HDR images in general, and currently the Radiance
|
||||||
// the Radiance .HDR file format, although the support is provided
|
// .HDR file format specifically. You can still load any file through the existing
|
||||||
// generically. You can still load any file through the existing interface;
|
// interface; if you attempt to load an HDR file, it will be automatically remapped
|
||||||
// if you attempt to load an HDR file, it will be automatically remapped to
|
// to LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;
|
||||||
// LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;
|
|
||||||
// both of these constants can be reconfigured through this interface:
|
// both of these constants can be reconfigured through this interface:
|
||||||
//
|
//
|
||||||
// stbi_hdr_to_ldr_gamma(2.2f);
|
// stbi_hdr_to_ldr_gamma(2.2f);
|
||||||
|
|
@ -257,7 +268,7 @@ RECENT REVISION HISTORY:
|
||||||
//
|
//
|
||||||
// By default we convert iphone-formatted PNGs back to RGB, even though
|
// By default we convert iphone-formatted PNGs back to RGB, even though
|
||||||
// they are internally encoded differently. You can disable this conversion
|
// they are internally encoded differently. You can disable this conversion
|
||||||
// by by calling stbi_convert_iphone_png_to_rgb(0), in which case
|
// by calling stbi_convert_iphone_png_to_rgb(0), in which case
|
||||||
// you will always just get the native iphone "format" through (which
|
// you will always just get the native iphone "format" through (which
|
||||||
// is BGR stored in RGB).
|
// is BGR stored in RGB).
|
||||||
//
|
//
|
||||||
|
|
@ -319,6 +330,7 @@ enum
|
||||||
STBI_rgb_alpha = 4
|
STBI_rgb_alpha = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
typedef unsigned char stbi_uc;
|
typedef unsigned char stbi_uc;
|
||||||
typedef unsigned short stbi_us;
|
typedef unsigned short stbi_us;
|
||||||
|
|
||||||
|
|
@ -355,10 +367,6 @@ typedef struct
|
||||||
|
|
||||||
STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels);
|
STBIDEF stbi_uc *stbi_load_from_memory (stbi_uc const *buffer, int len , int *x, int *y, int *channels_in_file, int desired_channels);
|
||||||
STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels);
|
STBIDEF stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk , void *user, int *x, int *y, int *channels_in_file, int desired_channels);
|
||||||
#ifndef STBI_NO_GIF
|
|
||||||
STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef STBI_NO_STDIO
|
#ifndef STBI_NO_STDIO
|
||||||
STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
|
STBIDEF stbi_uc *stbi_load (char const *filename, int *x, int *y, int *channels_in_file, int desired_channels);
|
||||||
|
|
@ -366,6 +374,14 @@ STBIDEF stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *channels_in
|
||||||
// for stbi_load_from_file, file pointer is left pointing immediately after image
|
// for stbi_load_from_file, file pointer is left pointing immediately after image
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef STBI_NO_GIF
|
||||||
|
STBIDEF stbi_uc *stbi_load_gif_from_memory(stbi_uc const *buffer, int len, int **delays, int *x, int *y, int *z, int *comp, int req_comp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef STBI_WINDOWS_UTF8
|
||||||
|
STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
//
|
//
|
||||||
// 16-bits-per-channel interface
|
// 16-bits-per-channel interface
|
||||||
|
|
@ -525,6 +541,12 @@ STBIDEF int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const ch
|
||||||
#define STBI_ASSERT(x) assert(x)
|
#define STBI_ASSERT(x) assert(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define STBI_EXTERN extern "C"
|
||||||
|
#else
|
||||||
|
#define STBI_EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
@ -649,14 +671,18 @@ static int stbi__cpuid3(void)
|
||||||
|
|
||||||
#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name
|
#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name
|
||||||
|
|
||||||
|
#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2)
|
||||||
static int stbi__sse2_available(void)
|
static int stbi__sse2_available(void)
|
||||||
{
|
{
|
||||||
int info3 = stbi__cpuid3();
|
int info3 = stbi__cpuid3();
|
||||||
return ((info3 >> 26) & 1) != 0;
|
return ((info3 >> 26) & 1) != 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#else // assume GCC-style if not VC++
|
#else // assume GCC-style if not VC++
|
||||||
#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))
|
#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))
|
||||||
|
|
||||||
|
#if !defined(STBI_NO_JPEG) && defined(STBI_SSE2)
|
||||||
static int stbi__sse2_available(void)
|
static int stbi__sse2_available(void)
|
||||||
{
|
{
|
||||||
// If we're even attempting to compile this on GCC/Clang, that means
|
// If we're even attempting to compile this on GCC/Clang, that means
|
||||||
|
|
@ -664,6 +690,8 @@ static int stbi__sse2_available(void)
|
||||||
// instructions at will, and so are we.
|
// instructions at will, and so are we.
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -1070,6 +1098,7 @@ static void stbi__vertical_flip(void *image, int w, int h, int bytes_per_pixel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef STBI_NO_GIF
|
||||||
static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel)
|
static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int bytes_per_pixel)
|
||||||
{
|
{
|
||||||
int slice;
|
int slice;
|
||||||
|
|
@ -1081,6 +1110,7 @@ static void stbi__vertical_flip_slices(void *image, int w, int h, int z, int byt
|
||||||
bytes += slice_size;
|
bytes += slice_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
static unsigned char *stbi__load_and_postprocess_8bit(stbi__context *s, int *x, int *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
|
|
@ -1131,7 +1161,7 @@ static stbi__uint16 *stbi__load_and_postprocess_16bit(stbi__context *s, int *x,
|
||||||
return (stbi__uint16 *) result;
|
return (stbi__uint16 *) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(STBI_NO_HDR) || !defined(STBI_NO_LINEAR)
|
#if !defined(STBI_NO_HDR) && !defined(STBI_NO_LINEAR)
|
||||||
static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp)
|
static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, int req_comp)
|
||||||
{
|
{
|
||||||
if (stbi__vertically_flip_on_load && result != NULL) {
|
if (stbi__vertically_flip_on_load && result != NULL) {
|
||||||
|
|
@ -1143,10 +1173,38 @@ static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, in
|
||||||
|
|
||||||
#ifndef STBI_NO_STDIO
|
#ifndef STBI_NO_STDIO
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
|
STBI_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide);
|
||||||
|
STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
|
STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input)
|
||||||
|
{
|
||||||
|
return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, bufferlen, NULL, NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static FILE *stbi__fopen(char const *filename, char const *mode)
|
static FILE *stbi__fopen(char const *filename, char const *mode)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
|
wchar_t wMode[64];
|
||||||
|
wchar_t wFilename[1024];
|
||||||
|
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if _MSC_VER >= 1400
|
||||||
|
if (0 != _wfopen_s(&f, wFilename, wMode))
|
||||||
|
f = 0;
|
||||||
|
#else
|
||||||
|
f = _wfopen(wFilename, wMode);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
if (0 != fopen_s(&f, filename, mode))
|
if (0 != fopen_s(&f, filename, mode))
|
||||||
f=0;
|
f=0;
|
||||||
#else
|
#else
|
||||||
|
|
@ -1539,18 +1597,18 @@ static unsigned char *stbi__convert_format(unsigned char *data, int img_n, int r
|
||||||
// convert source image with img_n components to one with req_comp components;
|
// convert source image with img_n components to one with req_comp components;
|
||||||
// avoid switch per pixel, so use switch per scanline and massive macros
|
// avoid switch per pixel, so use switch per scanline and massive macros
|
||||||
switch (STBI__COMBO(img_n, req_comp)) {
|
switch (STBI__COMBO(img_n, req_comp)) {
|
||||||
STBI__CASE(1,2) { dest[0]=src[0], dest[1]=255; } break;
|
STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=255; } break;
|
||||||
STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
||||||
STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=255; } break;
|
STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=255; } break;
|
||||||
STBI__CASE(2,1) { dest[0]=src[0]; } break;
|
STBI__CASE(2,1) { dest[0]=src[0]; } break;
|
||||||
STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
||||||
STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break;
|
STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break;
|
||||||
STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=255; } break;
|
STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=255; } break;
|
||||||
STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
STBI__CASE(3,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
||||||
STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = 255; } break;
|
STBI__CASE(3,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = 255; } break;
|
||||||
STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
STBI__CASE(4,1) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); } break;
|
||||||
STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]), dest[1] = src[3]; } break;
|
STBI__CASE(4,2) { dest[0]=stbi__compute_y(src[0],src[1],src[2]); dest[1] = src[3]; } break;
|
||||||
STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break;
|
STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break;
|
||||||
default: STBI_ASSERT(0);
|
default: STBI_ASSERT(0);
|
||||||
}
|
}
|
||||||
#undef STBI__CASE
|
#undef STBI__CASE
|
||||||
|
|
@ -1588,18 +1646,18 @@ static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int r
|
||||||
// convert source image with img_n components to one with req_comp components;
|
// convert source image with img_n components to one with req_comp components;
|
||||||
// avoid switch per pixel, so use switch per scanline and massive macros
|
// avoid switch per pixel, so use switch per scanline and massive macros
|
||||||
switch (STBI__COMBO(img_n, req_comp)) {
|
switch (STBI__COMBO(img_n, req_comp)) {
|
||||||
STBI__CASE(1,2) { dest[0]=src[0], dest[1]=0xffff; } break;
|
STBI__CASE(1,2) { dest[0]=src[0]; dest[1]=0xffff; } break;
|
||||||
STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
STBI__CASE(1,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
||||||
STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=0xffff; } break;
|
STBI__CASE(1,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=0xffff; } break;
|
||||||
STBI__CASE(2,1) { dest[0]=src[0]; } break;
|
STBI__CASE(2,1) { dest[0]=src[0]; } break;
|
||||||
STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
STBI__CASE(2,3) { dest[0]=dest[1]=dest[2]=src[0]; } break;
|
||||||
STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0], dest[3]=src[1]; } break;
|
STBI__CASE(2,4) { dest[0]=dest[1]=dest[2]=src[0]; dest[3]=src[1]; } break;
|
||||||
STBI__CASE(3,4) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2],dest[3]=0xffff; } break;
|
STBI__CASE(3,4) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2];dest[3]=0xffff; } break;
|
||||||
STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
|
STBI__CASE(3,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
|
||||||
STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]), dest[1] = 0xffff; } break;
|
STBI__CASE(3,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = 0xffff; } break;
|
||||||
STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
|
STBI__CASE(4,1) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); } break;
|
||||||
STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]), dest[1] = src[3]; } break;
|
STBI__CASE(4,2) { dest[0]=stbi__compute_y_16(src[0],src[1],src[2]); dest[1] = src[3]; } break;
|
||||||
STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break;
|
STBI__CASE(4,3) { dest[0]=src[0];dest[1]=src[1];dest[2]=src[2]; } break;
|
||||||
default: STBI_ASSERT(0);
|
default: STBI_ASSERT(0);
|
||||||
}
|
}
|
||||||
#undef STBI__CASE
|
#undef STBI__CASE
|
||||||
|
|
@ -1623,7 +1681,11 @@ static float *stbi__ldr_to_hdr(stbi_uc *data, int x, int y, int comp)
|
||||||
for (k=0; k < n; ++k) {
|
for (k=0; k < n; ++k) {
|
||||||
output[i*comp + k] = (float) (pow(data[i*comp+k]/255.0f, stbi__l2h_gamma) * stbi__l2h_scale);
|
output[i*comp + k] = (float) (pow(data[i*comp+k]/255.0f, stbi__l2h_gamma) * stbi__l2h_scale);
|
||||||
}
|
}
|
||||||
if (k < comp) output[i*comp + k] = data[i*comp+k]/255.0f;
|
}
|
||||||
|
if (n < comp) {
|
||||||
|
for (i=0; i < x*y; ++i) {
|
||||||
|
output[i*comp + n] = data[i*comp + n]/255.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
STBI_FREE(data);
|
STBI_FREE(data);
|
||||||
return output;
|
return output;
|
||||||
|
|
@ -3717,7 +3779,7 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
|
||||||
if (n == 1)
|
if (n == 1)
|
||||||
for (i=0; i < z->s->img_x; ++i) out[i] = y[i];
|
for (i=0; i < z->s->img_x; ++i) out[i] = y[i];
|
||||||
else
|
else
|
||||||
for (i=0; i < z->s->img_x; ++i) *out++ = y[i], *out++ = 255;
|
for (i=0; i < z->s->img_x; ++i) { *out++ = y[i]; *out++ = 255; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4731,7 +4793,7 @@ static void stbi__de_iphone(stbi__png *z)
|
||||||
static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
|
static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
|
||||||
{
|
{
|
||||||
stbi_uc palette[1024], pal_img_n=0;
|
stbi_uc palette[1024], pal_img_n=0;
|
||||||
stbi_uc has_trans=0, tc[3];
|
stbi_uc has_trans=0, tc[3]={0};
|
||||||
stbi__uint16 tc16[3];
|
stbi__uint16 tc16[3];
|
||||||
stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0;
|
stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0;
|
||||||
int first=1,k,interlace=0, color=0, is_iphone=0;
|
int first=1,k,interlace=0, color=0, is_iphone=0;
|
||||||
|
|
@ -5009,11 +5071,11 @@ static int stbi__high_bit(unsigned int z)
|
||||||
{
|
{
|
||||||
int n=0;
|
int n=0;
|
||||||
if (z == 0) return -1;
|
if (z == 0) return -1;
|
||||||
if (z >= 0x10000) n += 16, z >>= 16;
|
if (z >= 0x10000) { n += 16; z >>= 16; }
|
||||||
if (z >= 0x00100) n += 8, z >>= 8;
|
if (z >= 0x00100) { n += 8; z >>= 8; }
|
||||||
if (z >= 0x00010) n += 4, z >>= 4;
|
if (z >= 0x00010) { n += 4; z >>= 4; }
|
||||||
if (z >= 0x00004) n += 2, z >>= 2;
|
if (z >= 0x00004) { n += 2; z >>= 2; }
|
||||||
if (z >= 0x00002) n += 1, z >>= 1;
|
if (z >= 0x00002) { n += 1; z >>= 1; }
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5030,7 +5092,7 @@ static int stbi__bitcount(unsigned int a)
|
||||||
// extract an arbitrarily-aligned N-bit value (N=bits)
|
// extract an arbitrarily-aligned N-bit value (N=bits)
|
||||||
// from v, and then make it 8-bits long and fractionally
|
// from v, and then make it 8-bits long and fractionally
|
||||||
// extend it to full full range.
|
// extend it to full full range.
|
||||||
static int stbi__shiftsigned(int v, int shift, int bits)
|
static int stbi__shiftsigned(unsigned int v, int shift, int bits)
|
||||||
{
|
{
|
||||||
static unsigned int mul_table[9] = {
|
static unsigned int mul_table[9] = {
|
||||||
0,
|
0,
|
||||||
|
|
@ -5207,6 +5269,8 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
|
||||||
out[z++] = pal[color][0];
|
out[z++] = pal[color][0];
|
||||||
out[z++] = pal[color][1];
|
out[z++] = pal[color][1];
|
||||||
out[z++] = pal[color][2];
|
out[z++] = pal[color][2];
|
||||||
|
if (target == 4) out[z++] = 255;
|
||||||
|
if (i+1 == (int) s->img_x) break;
|
||||||
if((--bit_offset) < 0) {
|
if((--bit_offset) < 0) {
|
||||||
bit_offset = 7;
|
bit_offset = 7;
|
||||||
v = stbi__get8(s);
|
v = stbi__get8(s);
|
||||||
|
|
@ -5299,7 +5363,7 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
|
||||||
stbi_uc *p1 = out + j *s->img_x*target;
|
stbi_uc *p1 = out + j *s->img_x*target;
|
||||||
stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target;
|
stbi_uc *p2 = out + (s->img_y-1-j)*s->img_x*target;
|
||||||
for (i=0; i < (int) s->img_x*target; ++i) {
|
for (i=0; i < (int) s->img_x*target; ++i) {
|
||||||
t = p1[i], p1[i] = p2[i], p2[i] = t;
|
t = p1[i]; p1[i] = p2[i]; p2[i] = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5789,7 +5853,7 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req
|
||||||
// Else if n is 128, noop.
|
// Else if n is 128, noop.
|
||||||
// Endloop
|
// Endloop
|
||||||
|
|
||||||
// The RLE-compressed data is preceeded by a 2-byte data count for each row in the data,
|
// The RLE-compressed data is preceded by a 2-byte data count for each row in the data,
|
||||||
// which we're going to just skip.
|
// which we're going to just skip.
|
||||||
stbi__skip(s, h * channelCount * 2 );
|
stbi__skip(s, h * channelCount * 2 );
|
||||||
|
|
||||||
|
|
@ -6342,6 +6406,7 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
|
||||||
int first_frame;
|
int first_frame;
|
||||||
int pi;
|
int pi;
|
||||||
int pcount;
|
int pcount;
|
||||||
|
STBI_NOTUSED(req_comp);
|
||||||
|
|
||||||
// on first frame, any non-written pixels get the background colour (non-transparent)
|
// on first frame, any non-written pixels get the background colour (non-transparent)
|
||||||
first_frame = 0;
|
first_frame = 0;
|
||||||
|
|
@ -6352,9 +6417,9 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
|
||||||
g->history = (stbi_uc *) stbi__malloc(g->w * g->h);
|
g->history = (stbi_uc *) stbi__malloc(g->w * g->h);
|
||||||
if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");
|
if (g->out == 0) return stbi__errpuc("outofmem", "Out of memory");
|
||||||
|
|
||||||
// image is treated as "tranparent" at the start - ie, nothing overwrites the current background;
|
// image is treated as "transparent" at the start - ie, nothing overwrites the current background;
|
||||||
// background colour is only used for pixels that are not rendered first frame, after that "background"
|
// background colour is only used for pixels that are not rendered first frame, after that "background"
|
||||||
// color refers to teh color that was there the previous frame.
|
// color refers to the color that was there the previous frame.
|
||||||
memset( g->out, 0x00, 4 * g->w * g->h );
|
memset( g->out, 0x00, 4 * g->w * g->h );
|
||||||
memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent)
|
memset( g->background, 0x00, 4 * g->w * g->h ); // state of the background (starts transparent)
|
||||||
memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
|
memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
|
||||||
|
|
@ -6565,6 +6630,7 @@ static void *stbi__gif_load(stbi__context *s, int *x, int *y, int *comp, int req
|
||||||
stbi_uc *u = 0;
|
stbi_uc *u = 0;
|
||||||
stbi__gif g;
|
stbi__gif g;
|
||||||
memset(&g, 0, sizeof(g));
|
memset(&g, 0, sizeof(g));
|
||||||
|
STBI_NOTUSED(ri);
|
||||||
|
|
||||||
u = stbi__gif_load_next(s, &g, comp, req_comp, 0);
|
u = stbi__gif_load_next(s, &g, comp, req_comp, 0);
|
||||||
if (u == (stbi_uc *) s) u = 0; // end of animated gif marker
|
if (u == (stbi_uc *) s) u = 0; // end of animated gif marker
|
||||||
|
|
@ -7238,6 +7304,7 @@ STBIDEF int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *c, void *user
|
||||||
|
|
||||||
/*
|
/*
|
||||||
revision history:
|
revision history:
|
||||||
|
2.20 (2019-02-07) support utf8 filenames in Windows; fix warnings and platform ifdefs
|
||||||
2.19 (2018-02-11) fix warning
|
2.19 (2018-02-11) fix warning
|
||||||
2.18 (2018-01-30) fix warnings
|
2.18 (2018-01-30) fix warnings
|
||||||
2.17 (2018-01-29) change sbti__shiftsigned to avoid clang -O2 bug
|
2.17 (2018-01-29) change sbti__shiftsigned to avoid clang -O2 bug
|
||||||
|
|
|
||||||
145
src/external/stb_image_write.h
vendored
145
src/external/stb_image_write.h
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
/* stb_image_write - v1.09 - public domain - http://nothings.org/stb/stb_image_write.h
|
/* stb_image_write - v1.10 - public domain - http://nothings.org/stb/stb_image_write.h
|
||||||
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
|
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
|
||||||
no warranty implied; use at your own risk
|
no warranty implied; use at your own risk
|
||||||
|
|
||||||
|
|
@ -17,8 +17,7 @@
|
||||||
|
|
||||||
ABOUT:
|
ABOUT:
|
||||||
|
|
||||||
This header file is a library for writing images to C stdio. It could be
|
This header file is a library for writing images to C stdio or a callback.
|
||||||
adapted to write to memory or a general streaming interface; let me know.
|
|
||||||
|
|
||||||
The PNG output is not optimal; it is 20-50% larger than the file
|
The PNG output is not optimal; it is 20-50% larger than the file
|
||||||
written by a decent optimizing implementation; though providing a custom
|
written by a decent optimizing implementation; though providing a custom
|
||||||
|
|
@ -38,6 +37,14 @@ BUILDING:
|
||||||
The returned data will be freed with STBIW_FREE() (free() by default),
|
The returned data will be freed with STBIW_FREE() (free() by default),
|
||||||
so it must be heap allocated with STBIW_MALLOC() (malloc() by default),
|
so it must be heap allocated with STBIW_MALLOC() (malloc() by default),
|
||||||
|
|
||||||
|
UNICODE:
|
||||||
|
|
||||||
|
If compiling for Windows and you wish to use Unicode filenames, compile
|
||||||
|
with
|
||||||
|
#define STBIW_WINDOWS_UTF8
|
||||||
|
and pass utf8-encoded filenames. Call stbiw_convert_wchar_to_utf8 to convert
|
||||||
|
Windows wchar_t filenames to utf8.
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
|
|
||||||
There are five functions, one for each image file format:
|
There are five functions, one for each image file format:
|
||||||
|
|
@ -148,6 +155,8 @@ LICENSE
|
||||||
#ifndef INCLUDE_STB_IMAGE_WRITE_H
|
#ifndef INCLUDE_STB_IMAGE_WRITE_H
|
||||||
#define INCLUDE_STB_IMAGE_WRITE_H
|
#define INCLUDE_STB_IMAGE_WRITE_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
// if STB_IMAGE_WRITE_STATIC causes problems, try defining STBIWDEF to 'inline' or 'static inline'
|
// if STB_IMAGE_WRITE_STATIC causes problems, try defining STBIWDEF to 'inline' or 'static inline'
|
||||||
#ifndef STBIWDEF
|
#ifndef STBIWDEF
|
||||||
#ifdef STB_IMAGE_WRITE_STATIC
|
#ifdef STB_IMAGE_WRITE_STATIC
|
||||||
|
|
@ -173,6 +182,10 @@ STBIWDEF int stbi_write_bmp(char const *filename, int w, int h, int comp, const
|
||||||
STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data);
|
||||||
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
|
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
|
||||||
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
|
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
|
||||||
|
|
||||||
|
#ifdef STBI_WINDOWS_UTF8
|
||||||
|
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void stbi_write_func(void *context, void *data, int size);
|
typedef void stbi_write_func(void *context, void *data, int size);
|
||||||
|
|
@ -275,15 +288,52 @@ static void stbi__stdio_write(void *context, void *data, int size)
|
||||||
fwrite(data,1,size,(FILE*) context);
|
fwrite(data,1,size,(FILE*) context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stbi__start_write_file(stbi__write_context *s, const char *filename)
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define STBIW_EXTERN extern "C"
|
||||||
|
#else
|
||||||
|
#define STBIW_EXTERN extern
|
||||||
|
#endif
|
||||||
|
STBIW_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide);
|
||||||
|
STBIW_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default);
|
||||||
|
|
||||||
|
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input)
|
||||||
|
{
|
||||||
|
return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, bufferlen, NULL, NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static FILE *stbiw__fopen(char const *filename, char const *mode)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
#ifdef STBI_MSC_SECURE_CRT
|
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||||
if (fopen_s(&f, filename, "wb"))
|
wchar_t wMode[64];
|
||||||
f = NULL;
|
wchar_t wFilename[1024];
|
||||||
|
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if _MSC_VER >= 1400
|
||||||
|
if (0 != _wfopen_s(&f, wFilename, wMode))
|
||||||
|
f = 0;
|
||||||
#else
|
#else
|
||||||
f = fopen(filename, "wb");
|
f = _wfopen(wFilename, wMode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#elif defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
|
if (0 != fopen_s(&f, filename, mode))
|
||||||
|
f=0;
|
||||||
|
#else
|
||||||
|
f = fopen(filename, mode);
|
||||||
|
#endif
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int stbi__start_write_file(stbi__write_context *s, const char *filename)
|
||||||
|
{
|
||||||
|
FILE *f = stbiw__fopen(filename, "wb");
|
||||||
stbi__start_write_callbacks(s, stbi__stdio_write, (void *) f);
|
stbi__start_write_callbacks(s, stbi__stdio_write, (void *) f);
|
||||||
return f != NULL;
|
return f != NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -552,7 +602,7 @@ STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const
|
||||||
|
|
||||||
#define stbiw__max(a, b) ((a) > (b) ? (a) : (b))
|
#define stbiw__max(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
|
||||||
void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
static void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
||||||
{
|
{
|
||||||
int exponent;
|
int exponent;
|
||||||
float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2]));
|
float maxcomp = stbiw__max(linear[0], stbiw__max(linear[1], linear[2]));
|
||||||
|
|
@ -569,7 +619,7 @@ void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char databyte)
|
static void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char databyte)
|
||||||
{
|
{
|
||||||
unsigned char lengthbyte = STBIW_UCHAR(length+128);
|
unsigned char lengthbyte = STBIW_UCHAR(length+128);
|
||||||
STBIW_ASSERT(length+128 <= 255);
|
STBIW_ASSERT(length+128 <= 255);
|
||||||
|
|
@ -577,7 +627,7 @@ void stbiw__write_run_data(stbi__write_context *s, int length, unsigned char dat
|
||||||
s->func(s->context, &databyte, 1);
|
s->func(s->context, &databyte, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *data)
|
static void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *data)
|
||||||
{
|
{
|
||||||
unsigned char lengthbyte = STBIW_UCHAR(length);
|
unsigned char lengthbyte = STBIW_UCHAR(length);
|
||||||
STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code
|
STBIW_ASSERT(length <= 128); // inconsistent with spec but consistent with official code
|
||||||
|
|
@ -585,7 +635,7 @@ void stbiw__write_dump_data(stbi__write_context *s, int length, unsigned char *d
|
||||||
s->func(s->context, data, length);
|
s->func(s->context, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline)
|
static void stbiw__write_hdr_scanline(stbi__write_context *s, int width, int ncomp, unsigned char *scratch, float *scanline)
|
||||||
{
|
{
|
||||||
unsigned char scanlineheader[4] = { 2, 2, 0, 0 };
|
unsigned char scanlineheader[4] = { 2, 2, 0, 0 };
|
||||||
unsigned char rgbe[4];
|
unsigned char rgbe[4];
|
||||||
|
|
@ -694,7 +744,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
|
||||||
s->func(s->context, buffer, len);
|
s->func(s->context, buffer, len);
|
||||||
|
|
||||||
for(i=0; i < y; i++)
|
for(i=0; i < y; i++)
|
||||||
stbiw__write_hdr_scanline(s, x, comp, scratch, data + comp*x*(stbi__flip_vertically_on_write ? y-1-i : i)*x);
|
stbiw__write_hdr_scanline(s, x, comp, scratch, data + comp*x*(stbi__flip_vertically_on_write ? y-1-i : i));
|
||||||
STBIW_FREE(scratch);
|
STBIW_FREE(scratch);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -809,7 +859,7 @@ static unsigned int stbiw__zhash(unsigned char *data)
|
||||||
|
|
||||||
#endif // STBIW_ZLIB_COMPRESS
|
#endif // STBIW_ZLIB_COMPRESS
|
||||||
|
|
||||||
unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality)
|
STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality)
|
||||||
{
|
{
|
||||||
#ifdef STBIW_ZLIB_COMPRESS
|
#ifdef STBIW_ZLIB_COMPRESS
|
||||||
// user provided a zlib compress implementation, use that
|
// user provided a zlib compress implementation, use that
|
||||||
|
|
@ -923,6 +973,9 @@ unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, int *out_l
|
||||||
|
|
||||||
static unsigned int stbiw__crc32(unsigned char *buffer, int len)
|
static unsigned int stbiw__crc32(unsigned char *buffer, int len)
|
||||||
{
|
{
|
||||||
|
#ifdef STBIW_CRC32
|
||||||
|
return STBIW_CRC32(buffer, len);
|
||||||
|
#else
|
||||||
static unsigned int crc_table[256] =
|
static unsigned int crc_table[256] =
|
||||||
{
|
{
|
||||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
|
||||||
|
|
@ -964,6 +1017,7 @@ static unsigned int stbiw__crc32(unsigned char *buffer, int len)
|
||||||
for (i=0; i < len; ++i)
|
for (i=0; i < len; ++i)
|
||||||
crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)];
|
crc = (crc >> 8) ^ crc_table[buffer[i] ^ (crc & 0xff)];
|
||||||
return ~crc;
|
return ~crc;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4)
|
#define stbiw__wpng4(o,a,b,c,d) ((o)[0]=STBIW_UCHAR(a),(o)[1]=STBIW_UCHAR(b),(o)[2]=STBIW_UCHAR(c),(o)[3]=STBIW_UCHAR(d),(o)+=4)
|
||||||
|
|
@ -994,9 +1048,15 @@ static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int
|
||||||
int type = mymap[filter_type];
|
int type = mymap[filter_type];
|
||||||
unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y);
|
unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y);
|
||||||
int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;
|
int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;
|
||||||
|
|
||||||
|
if (type==0) {
|
||||||
|
memcpy(line_buffer, z, width*n);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// first loop isn't optimized since it's just one pixel
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: line_buffer[i] = z[i]; break;
|
|
||||||
case 1: line_buffer[i] = z[i]; break;
|
case 1: line_buffer[i] = z[i]; break;
|
||||||
case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;
|
case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;
|
||||||
case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break;
|
case 3: line_buffer[i] = z[i] - (z[i-signed_stride]>>1); break;
|
||||||
|
|
@ -1005,20 +1065,17 @@ static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int
|
||||||
case 6: line_buffer[i] = z[i]; break;
|
case 6: line_buffer[i] = z[i]; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i=n; i < width*n; ++i) {
|
switch (type) {
|
||||||
switch (type) {
|
case 1: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-n]; break;
|
||||||
case 0: line_buffer[i] = z[i]; break;
|
case 2: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - z[i-signed_stride]; break;
|
||||||
case 1: line_buffer[i] = z[i] - z[i-n]; break;
|
case 3: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break;
|
||||||
case 2: line_buffer[i] = z[i] - z[i-signed_stride]; break;
|
case 4: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break;
|
||||||
case 3: line_buffer[i] = z[i] - ((z[i-n] + z[i-signed_stride])>>1); break;
|
case 5: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - (z[i-n]>>1); break;
|
||||||
case 4: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], z[i-signed_stride], z[i-signed_stride-n]); break;
|
case 6: for (i=n; i < width*n; ++i) line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break;
|
||||||
case 5: line_buffer[i] = z[i] - (z[i-n]>>1); break;
|
|
||||||
case 6: line_buffer[i] = z[i] - stbiw__paeth(z[i-n], 0,0); break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
|
STBIWDEF unsigned char *stbi_write_png_to_mem(const unsigned char *pixels, int stride_bytes, int x, int y, int n, int *out_len)
|
||||||
{
|
{
|
||||||
int force_filter = stbi_write_force_png_filter;
|
int force_filter = stbi_write_force_png_filter;
|
||||||
int ctype[5] = { -1, 0, 4, 2, 6 };
|
int ctype[5] = { -1, 0, 4, 2, 6 };
|
||||||
|
|
@ -1040,11 +1097,11 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
|
||||||
int filter_type;
|
int filter_type;
|
||||||
if (force_filter > -1) {
|
if (force_filter > -1) {
|
||||||
filter_type = force_filter;
|
filter_type = force_filter;
|
||||||
stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, force_filter, line_buffer);
|
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, force_filter, line_buffer);
|
||||||
} else { // Estimate the best filter by running through all of them:
|
} else { // Estimate the best filter by running through all of them:
|
||||||
int best_filter = 0, best_filter_val = 0x7fffffff, est, i;
|
int best_filter = 0, best_filter_val = 0x7fffffff, est, i;
|
||||||
for (filter_type = 0; filter_type < 5; filter_type++) {
|
for (filter_type = 0; filter_type < 5; filter_type++) {
|
||||||
stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, filter_type, line_buffer);
|
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, filter_type, line_buffer);
|
||||||
|
|
||||||
// Estimate the entropy of the line using this filter; the less, the better.
|
// Estimate the entropy of the line using this filter; the less, the better.
|
||||||
est = 0;
|
est = 0;
|
||||||
|
|
@ -1057,7 +1114,7 @@ unsigned char *stbi_write_png_to_mem(unsigned char *pixels, int stride_bytes, in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it
|
if (filter_type != best_filter) { // If the last iteration already got us the best filter, don't redo it
|
||||||
stbiw__encode_png_line(pixels, stride_bytes, x, y, j, n, best_filter, line_buffer);
|
stbiw__encode_png_line((unsigned char*)(pixels), stride_bytes, x, y, j, n, best_filter, line_buffer);
|
||||||
filter_type = best_filter;
|
filter_type = best_filter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1109,14 +1166,10 @@ STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int len;
|
int len;
|
||||||
unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);
|
unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len);
|
||||||
if (png == NULL) return 0;
|
if (png == NULL) return 0;
|
||||||
#ifdef STBI_MSC_SECURE_CRT
|
|
||||||
if (fopen_s(&f, filename, "wb"))
|
f = stbiw__fopen(filename, "wb");
|
||||||
f = NULL;
|
|
||||||
#else
|
|
||||||
f = fopen(filename, "wb");
|
|
||||||
#endif
|
|
||||||
if (!f) { STBIW_FREE(png); return 0; }
|
if (!f) { STBIW_FREE(png); return 0; }
|
||||||
fwrite(png, 1, len, f);
|
fwrite(png, 1, len, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
@ -1128,7 +1181,7 @@ STBIWDEF int stbi_write_png(char const *filename, int x, int y, int comp, const
|
||||||
STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes)
|
STBIWDEF int stbi_write_png_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int stride_bytes)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
unsigned char *png = stbi_write_png_to_mem((unsigned char *) data, stride_bytes, x, y, comp, &len);
|
unsigned char *png = stbi_write_png_to_mem((const unsigned char *) data, stride_bytes, x, y, comp, &len);
|
||||||
if (png == NULL) return 0;
|
if (png == NULL) return 0;
|
||||||
func(context, png, len);
|
func(context, png, len);
|
||||||
STBIW_FREE(png);
|
STBIW_FREE(png);
|
||||||
|
|
@ -1423,15 +1476,17 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
|
||||||
for(x = 0; x < width; x += 8) {
|
for(x = 0; x < width; x += 8) {
|
||||||
float YDU[64], UDU[64], VDU[64];
|
float YDU[64], UDU[64], VDU[64];
|
||||||
for(row = y, pos = 0; row < y+8; ++row) {
|
for(row = y, pos = 0; row < y+8; ++row) {
|
||||||
|
int p;
|
||||||
|
if(row < height) {
|
||||||
|
p = (stbi__flip_vertically_on_write ? (height-1-row) : row)*width*comp;
|
||||||
|
} else {
|
||||||
|
// row >= height => use last input row (=> first if flipping)
|
||||||
|
p = stbi__flip_vertically_on_write ? 0 : ((height-1)*width*comp);
|
||||||
|
}
|
||||||
for(col = x; col < x+8; ++col, ++pos) {
|
for(col = x; col < x+8; ++col, ++pos) {
|
||||||
int p = (stbi__flip_vertically_on_write ? height-1-row : row)*width*comp + col*comp;
|
|
||||||
float r, g, b;
|
float r, g, b;
|
||||||
if(row >= height) {
|
// if col >= width => use pixel from last input column
|
||||||
p -= width*comp*(row+1 - height);
|
p += ((col < width) ? col : (width-1))*comp;
|
||||||
}
|
|
||||||
if(col >= width) {
|
|
||||||
p -= comp*(col+1 - width);
|
|
||||||
}
|
|
||||||
|
|
||||||
r = imageData[p+0];
|
r = imageData[p+0];
|
||||||
g = imageData[p+ofsG];
|
g = imageData[p+ofsG];
|
||||||
|
|
@ -1483,6 +1538,8 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const
|
||||||
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
|
||||||
/* Revision history
|
/* Revision history
|
||||||
|
1.10 (2019-02-07)
|
||||||
|
support utf8 filenames in Windows; fix warnings and platform ifdefs
|
||||||
1.09 (2018-02-11)
|
1.09 (2018-02-11)
|
||||||
fix typo in zlib quality API, improve STB_I_W_STATIC in C++
|
fix typo in zlib quality API, improve STB_I_W_STATIC in C++
|
||||||
1.08 (2018-01-29)
|
1.08 (2018-01-29)
|
||||||
|
|
|
||||||
152
src/external/stb_perlin.h
vendored
152
src/external/stb_perlin.h
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
// stb_perlin.h - v0.3 - perlin noise
|
// stb_perlin.h - v0.4 - perlin noise
|
||||||
// public domain single-file C implementation by Sean Barrett
|
// public domain single-file C implementation by Sean Barrett
|
||||||
//
|
//
|
||||||
// LICENSE
|
// LICENSE
|
||||||
|
|
@ -32,6 +32,19 @@
|
||||||
// details of the implementation, even if you ask for larger or no
|
// details of the implementation, even if you ask for larger or no
|
||||||
// wrapping.)
|
// wrapping.)
|
||||||
//
|
//
|
||||||
|
// float stb_perlin_noise3_seed( float x,
|
||||||
|
// float y,
|
||||||
|
// float z,
|
||||||
|
// int x_wrap=0,
|
||||||
|
// int y_wrap=0,
|
||||||
|
// int z_wrap=0,
|
||||||
|
// int seed)
|
||||||
|
//
|
||||||
|
// As above, but 'seed' selects from multiple different variations of the
|
||||||
|
// noise function. The current implementation only uses the bottom 8 bits
|
||||||
|
// of 'seed', but possibly in the future more bits will be used.
|
||||||
|
//
|
||||||
|
//
|
||||||
// Fractal Noise:
|
// Fractal Noise:
|
||||||
//
|
//
|
||||||
// Three common fractal noise functions are included, which produce
|
// Three common fractal noise functions are included, which produce
|
||||||
|
|
@ -40,16 +53,13 @@
|
||||||
// 'octaves' times, so this parameter will affect runtime.
|
// 'octaves' times, so this parameter will affect runtime.
|
||||||
//
|
//
|
||||||
// float stb_perlin_ridge_noise3(float x, float y, float z,
|
// float stb_perlin_ridge_noise3(float x, float y, float z,
|
||||||
// float lacunarity, float gain, float offset, int octaves,
|
// float lacunarity, float gain, float offset, int octaves)
|
||||||
// int x_wrap, int y_wrap, int z_wrap);
|
|
||||||
//
|
//
|
||||||
// float stb_perlin_fbm_noise3(float x, float y, float z,
|
// float stb_perlin_fbm_noise3(float x, float y, float z,
|
||||||
// float lacunarity, float gain, int octaves,
|
// float lacunarity, float gain, int octaves)
|
||||||
// int x_wrap, int y_wrap, int z_wrap);
|
|
||||||
//
|
//
|
||||||
// float stb_perlin_turbulence_noise3(float x, float y, float z,
|
// float stb_perlin_turbulence_noise3(float x, float y, float z,
|
||||||
// float lacunarity, float gain,int octaves,
|
// float lacunarity, float gain, int octaves)
|
||||||
// int x_wrap, int y_wrap, int z_wrap);
|
|
||||||
//
|
//
|
||||||
// Typical values to start playing with:
|
// Typical values to start playing with:
|
||||||
// octaves = 6 -- number of "octaves" of noise3() to sum
|
// octaves = 6 -- number of "octaves" of noise3() to sum
|
||||||
|
|
@ -60,6 +70,7 @@
|
||||||
//
|
//
|
||||||
// Contributors:
|
// Contributors:
|
||||||
// Jack Mott - additional noise functions
|
// Jack Mott - additional noise functions
|
||||||
|
// Jordan Peck - seeded noise
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -67,18 +78,19 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
extern float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap);
|
extern float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap);
|
||||||
extern float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float gain, float offset, int octaves,int x_wrap, int y_wrap, int z_wrap);
|
extern float stb_perlin_ridge_noise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves);
|
||||||
extern float stb_perlin_fbm_noise3(float x, float y, float z,float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap);
|
extern float stb_perlin_fbm_noise3(float x, float y, float z, float lacunarity, float gain, int octaves);
|
||||||
extern float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap);
|
extern float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef STB_PERLIN_IMPLEMENTATION
|
#ifdef STB_PERLIN_IMPLEMENTATION
|
||||||
|
|
||||||
|
#include <math.h> // fabs()
|
||||||
|
|
||||||
// not same permutation table as Perlin's reference to avoid copyright issues;
|
// not same permutation table as Perlin's reference to avoid copyright issues;
|
||||||
// Perlin's table can be found at http://mrl.nyu.edu/~perlin/noise/
|
// Perlin's table can be found at http://mrl.nyu.edu/~perlin/noise/
|
||||||
// @OPTIMIZE: should this be unsigned char instead of int for cache?
|
|
||||||
static unsigned char stb__perlin_randtab[512] =
|
static unsigned char stb__perlin_randtab[512] =
|
||||||
{
|
{
|
||||||
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
||||||
|
|
@ -115,6 +127,51 @@ static unsigned char stb__perlin_randtab[512] =
|
||||||
131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62,
|
131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62,
|
||||||
27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135,
|
27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135,
|
||||||
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// perlin's gradient has 12 cases so some get used 1/16th of the time
|
||||||
|
// and some 2/16ths. We reduce bias by changing those fractions
|
||||||
|
// to 5/64ths and 6/64ths
|
||||||
|
|
||||||
|
// this array is designed to match the previous implementation
|
||||||
|
// of gradient hash: indices[stb__perlin_randtab[i]&63]
|
||||||
|
static unsigned char stb__perlin_randtab_grad_idx[512] =
|
||||||
|
{
|
||||||
|
7, 9, 5, 0, 11, 1, 6, 9, 3, 9, 11, 1, 8, 10, 4, 7,
|
||||||
|
8, 6, 1, 5, 3, 10, 9, 10, 0, 8, 4, 1, 5, 2, 7, 8,
|
||||||
|
7, 11, 9, 10, 1, 0, 4, 7, 5, 0, 11, 6, 1, 4, 2, 8,
|
||||||
|
8, 10, 4, 9, 9, 2, 5, 7, 9, 1, 7, 2, 2, 6, 11, 5,
|
||||||
|
5, 4, 6, 9, 0, 1, 1, 0, 7, 6, 9, 8, 4, 10, 3, 1,
|
||||||
|
2, 8, 8, 9, 10, 11, 5, 11, 11, 2, 6, 10, 3, 4, 2, 4,
|
||||||
|
9, 10, 3, 2, 6, 3, 6, 10, 5, 3, 4, 10, 11, 2, 9, 11,
|
||||||
|
1, 11, 10, 4, 9, 4, 11, 0, 4, 11, 4, 0, 0, 0, 7, 6,
|
||||||
|
10, 4, 1, 3, 11, 5, 3, 4, 2, 9, 1, 3, 0, 1, 8, 0,
|
||||||
|
6, 7, 8, 7, 0, 4, 6, 10, 8, 2, 3, 11, 11, 8, 0, 2,
|
||||||
|
4, 8, 3, 0, 0, 10, 6, 1, 2, 2, 4, 5, 6, 0, 1, 3,
|
||||||
|
11, 9, 5, 5, 9, 6, 9, 8, 3, 8, 1, 8, 9, 6, 9, 11,
|
||||||
|
10, 7, 5, 6, 5, 9, 1, 3, 7, 0, 2, 10, 11, 2, 6, 1,
|
||||||
|
3, 11, 7, 7, 2, 1, 7, 3, 0, 8, 1, 1, 5, 0, 6, 10,
|
||||||
|
11, 11, 0, 2, 7, 0, 10, 8, 3, 5, 7, 1, 11, 1, 0, 7,
|
||||||
|
9, 0, 11, 5, 10, 3, 2, 3, 5, 9, 7, 9, 8, 4, 6, 5,
|
||||||
|
|
||||||
|
// and a second copy so we don't need an extra mask or static initializer
|
||||||
|
7, 9, 5, 0, 11, 1, 6, 9, 3, 9, 11, 1, 8, 10, 4, 7,
|
||||||
|
8, 6, 1, 5, 3, 10, 9, 10, 0, 8, 4, 1, 5, 2, 7, 8,
|
||||||
|
7, 11, 9, 10, 1, 0, 4, 7, 5, 0, 11, 6, 1, 4, 2, 8,
|
||||||
|
8, 10, 4, 9, 9, 2, 5, 7, 9, 1, 7, 2, 2, 6, 11, 5,
|
||||||
|
5, 4, 6, 9, 0, 1, 1, 0, 7, 6, 9, 8, 4, 10, 3, 1,
|
||||||
|
2, 8, 8, 9, 10, 11, 5, 11, 11, 2, 6, 10, 3, 4, 2, 4,
|
||||||
|
9, 10, 3, 2, 6, 3, 6, 10, 5, 3, 4, 10, 11, 2, 9, 11,
|
||||||
|
1, 11, 10, 4, 9, 4, 11, 0, 4, 11, 4, 0, 0, 0, 7, 6,
|
||||||
|
10, 4, 1, 3, 11, 5, 3, 4, 2, 9, 1, 3, 0, 1, 8, 0,
|
||||||
|
6, 7, 8, 7, 0, 4, 6, 10, 8, 2, 3, 11, 11, 8, 0, 2,
|
||||||
|
4, 8, 3, 0, 0, 10, 6, 1, 2, 2, 4, 5, 6, 0, 1, 3,
|
||||||
|
11, 9, 5, 5, 9, 6, 9, 8, 3, 8, 1, 8, 9, 6, 9, 11,
|
||||||
|
10, 7, 5, 6, 5, 9, 1, 3, 7, 0, 2, 10, 11, 2, 6, 1,
|
||||||
|
3, 11, 7, 7, 2, 1, 7, 3, 0, 8, 1, 1, 5, 0, 6, 10,
|
||||||
|
11, 11, 0, 2, 7, 0, 10, 8, 3, 5, 7, 1, 11, 1, 0, 7,
|
||||||
|
9, 0, 11, 5, 10, 3, 2, 3, 5, 9, 7, 9, 8, 4, 6, 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
static float stb__perlin_lerp(float a, float b, float t)
|
static float stb__perlin_lerp(float a, float b, float t)
|
||||||
|
|
@ -124,12 +181,12 @@ static float stb__perlin_lerp(float a, float b, float t)
|
||||||
|
|
||||||
static int stb__perlin_fastfloor(float a)
|
static int stb__perlin_fastfloor(float a)
|
||||||
{
|
{
|
||||||
int ai = (int) a;
|
int ai = (int) a;
|
||||||
return (a < ai) ? ai-1 : ai;
|
return (a < ai) ? ai-1 : ai;
|
||||||
}
|
}
|
||||||
|
|
||||||
// different grad function from Perlin's, but easy to modify to match reference
|
// different grad function from Perlin's, but easy to modify to match reference
|
||||||
static float stb__perlin_grad(int hash, float x, float y, float z)
|
static float stb__perlin_grad(int grad_idx, float x, float y, float z)
|
||||||
{
|
{
|
||||||
static float basis[12][4] =
|
static float basis[12][4] =
|
||||||
{
|
{
|
||||||
|
|
@ -147,26 +204,11 @@ static float stb__perlin_grad(int hash, float x, float y, float z)
|
||||||
{ 0,-1,-1 },
|
{ 0,-1,-1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
// perlin's gradient has 12 cases so some get used 1/16th of the time
|
float *grad = basis[grad_idx];
|
||||||
// and some 2/16ths. We reduce bias by changing those fractions
|
|
||||||
// to 5/64ths and 6/64ths, and the same 4 cases get the extra weight.
|
|
||||||
static unsigned char indices[64] =
|
|
||||||
{
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
0,9,1,11,
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
0,1,2,3,4,5,6,7,8,9,10,11,
|
|
||||||
};
|
|
||||||
|
|
||||||
// if you use reference permutation table, change 63 below to 15 to match reference
|
|
||||||
// (this is why the ordering of the table above is funky)
|
|
||||||
float *grad = basis[indices[hash & 63]];
|
|
||||||
return grad[0]*x + grad[1]*y + grad[2]*z;
|
return grad[0]*x + grad[1]*y + grad[2]*z;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap)
|
float stb_perlin_noise3_internal(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, unsigned char seed)
|
||||||
{
|
{
|
||||||
float u,v,w;
|
float u,v,w;
|
||||||
float n000,n001,n010,n011,n100,n101,n110,n111;
|
float n000,n001,n010,n011,n100,n101,n110,n111;
|
||||||
|
|
@ -190,22 +232,22 @@ float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z
|
||||||
y -= py; v = stb__perlin_ease(y);
|
y -= py; v = stb__perlin_ease(y);
|
||||||
z -= pz; w = stb__perlin_ease(z);
|
z -= pz; w = stb__perlin_ease(z);
|
||||||
|
|
||||||
r0 = stb__perlin_randtab[x0];
|
r0 = stb__perlin_randtab[x0+seed];
|
||||||
r1 = stb__perlin_randtab[x1];
|
r1 = stb__perlin_randtab[x1+seed];
|
||||||
|
|
||||||
r00 = stb__perlin_randtab[r0+y0];
|
r00 = stb__perlin_randtab[r0+y0];
|
||||||
r01 = stb__perlin_randtab[r0+y1];
|
r01 = stb__perlin_randtab[r0+y1];
|
||||||
r10 = stb__perlin_randtab[r1+y0];
|
r10 = stb__perlin_randtab[r1+y0];
|
||||||
r11 = stb__perlin_randtab[r1+y1];
|
r11 = stb__perlin_randtab[r1+y1];
|
||||||
|
|
||||||
n000 = stb__perlin_grad(stb__perlin_randtab[r00+z0], x , y , z );
|
n000 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z0], x , y , z );
|
||||||
n001 = stb__perlin_grad(stb__perlin_randtab[r00+z1], x , y , z-1 );
|
n001 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z1], x , y , z-1 );
|
||||||
n010 = stb__perlin_grad(stb__perlin_randtab[r01+z0], x , y-1, z );
|
n010 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z0], x , y-1, z );
|
||||||
n011 = stb__perlin_grad(stb__perlin_randtab[r01+z1], x , y-1, z-1 );
|
n011 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z1], x , y-1, z-1 );
|
||||||
n100 = stb__perlin_grad(stb__perlin_randtab[r10+z0], x-1, y , z );
|
n100 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z0], x-1, y , z );
|
||||||
n101 = stb__perlin_grad(stb__perlin_randtab[r10+z1], x-1, y , z-1 );
|
n101 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z1], x-1, y , z-1 );
|
||||||
n110 = stb__perlin_grad(stb__perlin_randtab[r11+z0], x-1, y-1, z );
|
n110 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z0], x-1, y-1, z );
|
||||||
n111 = stb__perlin_grad(stb__perlin_randtab[r11+z1], x-1, y-1, z-1 );
|
n111 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z1], x-1, y-1, z-1 );
|
||||||
|
|
||||||
n00 = stb__perlin_lerp(n000,n001,w);
|
n00 = stb__perlin_lerp(n000,n001,w);
|
||||||
n01 = stb__perlin_lerp(n010,n011,w);
|
n01 = stb__perlin_lerp(n010,n011,w);
|
||||||
|
|
@ -218,7 +260,17 @@ float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z
|
||||||
return stb__perlin_lerp(n0,n1,u);
|
return stb__perlin_lerp(n0,n1,u);
|
||||||
}
|
}
|
||||||
|
|
||||||
float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float gain, float offset, int octaves,int x_wrap, int y_wrap, int z_wrap)
|
float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap)
|
||||||
|
{
|
||||||
|
return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float stb_perlin_noise3_seed(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, int seed)
|
||||||
|
{
|
||||||
|
return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap, (unsigned char) seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
float stb_perlin_ridge_noise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float frequency = 1.0f;
|
float frequency = 1.0f;
|
||||||
|
|
@ -227,9 +279,8 @@ float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
|
|
||||||
for (i = 0; i < octaves; i++) {
|
for (i = 0; i < octaves; i++) {
|
||||||
float r = (float)(stb_perlin_noise3(x*frequency,y*frequency,z*frequency,x_wrap,y_wrap,z_wrap));
|
float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i);
|
||||||
r = r<0 ? -r : r; // fabs()
|
r = offset - (float) fabs(r);
|
||||||
r = offset - r;
|
|
||||||
r = r*r;
|
r = r*r;
|
||||||
sum += r*amplitude*prev;
|
sum += r*amplitude*prev;
|
||||||
prev = r;
|
prev = r;
|
||||||
|
|
@ -239,7 +290,7 @@ float stb_perlin_ridge_noise3(float x, float y, float z,float lacunarity, float
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stb_perlin_fbm_noise3(float x, float y, float z,float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap)
|
float stb_perlin_fbm_noise3(float x, float y, float z, float lacunarity, float gain, int octaves)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float frequency = 1.0f;
|
float frequency = 1.0f;
|
||||||
|
|
@ -247,14 +298,14 @@ float stb_perlin_fbm_noise3(float x, float y, float z,float lacunarity, float ga
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
|
|
||||||
for (i = 0; i < octaves; i++) {
|
for (i = 0; i < octaves; i++) {
|
||||||
sum += stb_perlin_noise3(x*frequency,y*frequency,z*frequency,x_wrap,y_wrap,z_wrap)*amplitude;
|
sum += stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i)*amplitude;
|
||||||
frequency *= lacunarity;
|
frequency *= lacunarity;
|
||||||
amplitude *= gain;
|
amplitude *= gain;
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap)
|
float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float frequency = 1.0f;
|
float frequency = 1.0f;
|
||||||
|
|
@ -262,9 +313,8 @@ float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity,
|
||||||
float sum = 0.0f;
|
float sum = 0.0f;
|
||||||
|
|
||||||
for (i = 0; i < octaves; i++) {
|
for (i = 0; i < octaves; i++) {
|
||||||
float r = stb_perlin_noise3(x*frequency,y*frequency,z*frequency,x_wrap,y_wrap,z_wrap)*amplitude;
|
float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i)*amplitude;
|
||||||
r = r<0 ? -r : r; // fabs()
|
sum += (float) fabs(r);
|
||||||
sum += r;
|
|
||||||
frequency *= lacunarity;
|
frequency *= lacunarity;
|
||||||
amplitude *= gain;
|
amplitude *= gain;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
src/external/stb_rect_pack.h
vendored
9
src/external/stb_rect_pack.h
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
// stb_rect_pack.h - v0.11 - public domain - rectangle packing
|
// stb_rect_pack.h - v0.99 - public domain - rectangle packing
|
||||||
// Sean Barrett 2014
|
// Sean Barrett 2014
|
||||||
//
|
//
|
||||||
// Useful for e.g. packing rectangular textures into an atlas.
|
// Useful for e.g. packing rectangular textures into an atlas.
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
//
|
//
|
||||||
// Version history:
|
// Version history:
|
||||||
//
|
//
|
||||||
|
// 0.99 (2019-02-07) warning fixes
|
||||||
// 0.11 (2017-03-03) return packing success/fail result
|
// 0.11 (2017-03-03) return packing success/fail result
|
||||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||||
// 0.09 (2016-08-27) fix compiler warnings
|
// 0.09 (2016-08-27) fix compiler warnings
|
||||||
|
|
@ -492,17 +493,14 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
|
||||||
STBRP_ASSERT(cur->next == NULL);
|
STBRP_ASSERT(cur->next == NULL);
|
||||||
|
|
||||||
{
|
{
|
||||||
stbrp_node *L1 = NULL, *L2 = NULL;
|
|
||||||
int count=0;
|
int count=0;
|
||||||
cur = context->active_head;
|
cur = context->active_head;
|
||||||
while (cur) {
|
while (cur) {
|
||||||
L1 = cur;
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
cur = context->free_head;
|
cur = context->free_head;
|
||||||
while (cur) {
|
while (cur) {
|
||||||
L2 = cur;
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
|
|
@ -544,9 +542,6 @@ STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int nu
|
||||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||||
for (i=0; i < num_rects; ++i) {
|
for (i=0; i < num_rects; ++i) {
|
||||||
rects[i].was_packed = i;
|
rects[i].was_packed = i;
|
||||||
#ifndef STBRP_LARGE_RECTS
|
|
||||||
STBRP_ASSERT(rects[i].w <= 0xffff && rects[i].h <= 0xffff);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort according to heuristic
|
// sort according to heuristic
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue