Skip to content

Commit bac46df

Browse files
authored
Update compile_shader.bat
Try to fix the compile_shader.bat
1 parent 0a1e773 commit bac46df

File tree

1 file changed

+32
-39
lines changed

1 file changed

+32
-39
lines changed

tools/compile_shader.bat

+32-39
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@
66
@echo off
77
SETLOCAL EnableDelayedExpansion
88

9-
:: Go to usage function if no arguments have been given to the script
10-
IF [%1]==[] GOTO usage
9+
:: If no arguments have been given to the script
10+
IF "%~1"=="" (
11+
echo ERROR: missing arguments, use as follows: %~nx0 ^<ShaderFile^> ^<Mode^> 1>&2
12+
ENDLOCAL
13+
EXIT /B 1
14+
)
1115

12-
:: Check if input file exists before continuing
13-
IF NOT EXIST %1 GOTO fnotfound
16+
:: Check if file exists
17+
IF NOT EXIST "%~1" (
18+
echo ERROR: shader file not found: %~1 1>&2
19+
ENDLOCAL
20+
EXIT /B 2
21+
)
1422

15-
SET SHADERTYPE=%~x1
16-
SET SHADERTYPE=%SHADERTYPE:~1%
23+
:: Extract the shader type (file extension without the dot)
24+
SET "SHADERTYPE=%~x1"
25+
SET "SHADERTYPE=%SHADERTYPE:~1%"
1726

1827
echo // -----------------------------------------------------------------------------
1928
echo // Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
@@ -25,44 +34,28 @@ echo.
2534
echo #include "MLX42/MLX42_Int.h"
2635
echo.
2736

28-
REM Read the shader version line
29-
SET VERSIONLINE=
30-
FOR /F "delims=" %%A IN (%1) DO (
31-
IF NOT DEFINED VERSIONLINE (
32-
SET VERSIONLINE=%%A
33-
SET "FIRSTLINE=1"
34-
) ELSE (
35-
IF !FIRSTLINE! NEQ 1 (
36-
IF "%%A" == "}" (
37-
echo "%%A";
38-
) ELSE (
39-
echo "%%A"
40-
)
41-
)
37+
:: Check the Mode argument (WASM specific output if Mode == 1)
38+
IF "%~2"=="1" (
39+
echo const char* %SHADERTYPE%_shader = "#version 300 es\n"
40+
echo "precision mediump float;\n"
41+
) ELSE (
42+
FOR /F "delims=" %%A IN ('more +0 "%~1"') DO (
43+
echo const char* %SHADERTYPE%_shader = "%%A\n"
44+
GOTO next
4245
)
4346
)
4447

45-
REM Output the shader declaration
46-
IF "%2"=="1" (
47-
echo const char* %SHADERTYPE%_shader = "#version 300 es\n"
48-
IF /I "%SHADERTYPE%"=="frag" (
49-
echo "precision mediump float;\n"
48+
:next
49+
:: Read and process the rest of the shader file
50+
FOR /F "usebackq delims=" %%A IN ("%~1") DO (
51+
IF NOT "%%A"=="" (
52+
IF "%%A"=="}" (
53+
echo "%%A";
54+
) ELSE (
55+
echo "%%A"
56+
)
5057
)
51-
) ELSE (
52-
echo const char* %SHADERTYPE%_shader = "%VERSIONLINE%\n"
5358
)
5459

5560
ENDLOCAL
5661
EXIT /B 0
57-
58-
:: usage function exits the script with exit code 3 (missing arguments)
59-
:usage
60-
echo ERROR: missing arguments, use as follows: %0 ^<ShaderFile^> ^<Mode^> 1>&2
61-
ENDLOCAL
62-
EXIT /B 3
63-
64-
:: fnotfound function exits the script with exit code 2 (file not found)
65-
:fnotfound
66-
echo ERROR: shader file not found: %1 1>&2
67-
ENDLOCAL
68-
EXIT /B 2

0 commit comments

Comments
 (0)