This commit is contained in:
Angel Ortigosa Perez
2026-02-12 17:45:06 +01:00
parent 6579882198
commit 2707e12133
80 changed files with 185 additions and 1489 deletions

View File

@@ -4,28 +4,19 @@
:: -----------------------------------------------------------------------------
@echo off
SETLOCAL EnableDelayedExpansion
SETLOCAL DisableDelayedExpansion
:: If no arguments have been given to the script
IF "%~1"=="" (
echo ERROR: missing arguments, use as follows: %~nx0 ^<ShaderFile^> ^<Mode^> 1>&2
ENDLOCAL
EXIT /B 1
)
:: go to usage function if no arguments have been given to the script
IF [%1]==[] GOTO usage
:: Check if file exists
IF NOT EXIST "%~1" (
echo ERROR: shader file not found: %~1 1>&2
ENDLOCAL
EXIT /B 2
)
:: check if input file exists before continuing
IF NOT EXIST %1 GOTO fnotfound
:: Extract the shader type (file extension without the dot)
SET "SHADERTYPE=%~x1"
SET "SHADERTYPE=%SHADERTYPE:~1%"
SET SHADERTYPE=%~x1
SET SHADERTYPE=%SHADERTYPE:~1%
echo // -----------------------------------------------------------------------------
echo // Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
echo // Codam Coding College, Amsterdam @ <2022-2023> by W2Wizard.
echo // See README in the root project for more information.
echo // -----------------------------------------------------------------------------
echo.
@@ -34,28 +25,23 @@ echo.
echo #include "MLX42/MLX42_Int.h"
echo.
:: Check the Mode argument (WASM specific output if Mode == 1)
IF "%~2"=="1" (
echo const char* %SHADERTYPE%_shader = "#version 300 es\n"
echo "precision mediump float;\n"
) ELSE (
FOR /F "delims=" %%A IN ('more +0 "%~1"') DO (
echo const char* %SHADERTYPE%_shader = "%%A\n"
GOTO next
)
)
:next
:: Read and process the rest of the shader file
FOR /F "usebackq delims=" %%A IN ("%~1") DO (
IF NOT "%%A"=="" (
IF "%%A"=="}" (
echo "%%A";
) ELSE (
echo "%%A"
)
)
FOR /F "delims=" %%A IN (%1) DO IF NOT DEFINED VERSIONLINE set "VERSIONLINE=%%A"
echo const char* %SHADERTYPE%_shader = "%VERSIONLINE%\n"
FOR /F "skip=1 delims=" %%A IN (%1) DO (
IF "%%A" == "}" (echo "%%A";) ELSE (echo "%%A")
)
ENDLOCAL
EXIT /B 0
:: usage function exits the script with exit code 3 (path not found)
:usage
echo ERROR: missing arguments, use as follows: %0 ^<ShaderFile^> 1>&2
ENDLOCAL
EXIT /B 3
:: fnotfound function exits the script with exit code 2 (file not found)
:fnotfound
echo ERROR: shader file not found: %1 1>&2
ENDLOCAL
EXIT /B 2

View File

@@ -4,41 +4,32 @@
# See README in the root project for more information.
# -----------------------------------------------------------------------------
# If no arguments have been given
if [ "$#" -ne 2 ]; then
echo "ERROR: missing arguments, use as follows: $0 <ShaderFile> <Mode>" 1>&2
exit 1
# If no arguments have been given, exit with error code 1
if [ "$#" -ne 1 ]; then
echo "ERROR: missing arguments, use as follows: $0 <ShaderFile>" 1>&2
exit 1
fi
# If file cannot be found
# If file cannot be found, exit with error code 2
if [ ! -f "$1" ]; then
echo "ERROR: shader file not found: $1" 1>&2
exit 2
echo "ERROR: shader file not found: $1" 1>&2
exit 2
fi
SHADERTYPE="${1##*.}"
echo "// -----------------------------------------------------------------------------"
echo "// Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard. "
echo "// See README in the root project for more information. "
echo "// Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard. "
echo "// See README in the root project for more information. "
echo "// -----------------------------------------------------------------------------"
echo ""
echo "// If you wish to modify this file edit the .vert or .frag file!"
echo ""
# Include the MLX42 header
echo "#include \"MLX42/MLX42_Int.h\""
echo ""
echo "const char* ${SHADERTYPE}_shader = \"$(sed -n '1{p;q;}' "$1")\\n\""
{
if [ "$2" -eq 1 ]; then # Output WASM specific lines
echo "const char* ${SHADERTYPE}_shader = \"#version 300 es\\n\""
echo " \"precision mediump float;\""
else # Non-Wasm, output the original shader version
echo "const char* ${SHADERTYPE}_shader = \"$(sed -n '1{p;q;}' "$1")\\n\""
fi
# Read the rest of the shader file
# Skip over first line
read
while IFS= read -r LINE; do
if [ ! "${LINE}" = "" ]; then
@@ -50,5 +41,4 @@ echo ""
fi
done
} < "$1"
exit 0