Skip to content

Commit

Permalink
Update compile_shader.bat
Browse files Browse the repository at this point in the history
Try to fix the compile_shader.bat
  • Loading branch information
W2Wizard authored Oct 16, 2024
1 parent 0a1e773 commit bac46df
Showing 1 changed file with 32 additions and 39 deletions.
71 changes: 32 additions & 39 deletions tools/compile_shader.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@
@echo off
SETLOCAL EnableDelayedExpansion

:: Go to usage function if no arguments have been given to the script
IF [%1]==[] GOTO usage
:: 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
)

:: Check if input file exists before continuing
IF NOT EXIST %1 GOTO fnotfound
:: Check if file exists
IF NOT EXIST "%~1" (
echo ERROR: shader file not found: %~1 1>&2
ENDLOCAL
EXIT /B 2
)

SET SHADERTYPE=%~x1
SET SHADERTYPE=%SHADERTYPE:~1%
:: Extract the shader type (file extension without the dot)
SET "SHADERTYPE=%~x1"
SET "SHADERTYPE=%SHADERTYPE:~1%"

echo // -----------------------------------------------------------------------------
echo // Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
Expand All @@ -25,44 +34,28 @@ echo.
echo #include "MLX42/MLX42_Int.h"
echo.

REM Read the shader version line
SET VERSIONLINE=
FOR /F "delims=" %%A IN (%1) DO (
IF NOT DEFINED VERSIONLINE (
SET VERSIONLINE=%%A
SET "FIRSTLINE=1"
) ELSE (
IF !FIRSTLINE! NEQ 1 (
IF "%%A" == "}" (
echo "%%A";
) ELSE (
echo "%%A"
)
)
:: 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
)
)

REM Output the shader declaration
IF "%2"=="1" (
echo const char* %SHADERTYPE%_shader = "#version 300 es\n"
IF /I "%SHADERTYPE%"=="frag" (
echo "precision mediump float;\n"
: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"
)
)
) ELSE (
echo const char* %SHADERTYPE%_shader = "%VERSIONLINE%\n"
)

ENDLOCAL
EXIT /B 0

:: usage function exits the script with exit code 3 (missing arguments)
:usage
echo ERROR: missing arguments, use as follows: %0 ^<ShaderFile^> ^<Mode^> 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

0 comments on commit bac46df

Please sign in to comment.