6
6
@ echo off
7
7
SETLOCAL EnableDelayedExpansion
8
8
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
+ )
11
15
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
+ )
14
22
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 % "
17
26
18
27
echo // -----------------------------------------------------------------------------
19
28
echo // Codam Coding College, Amsterdam @ 2022-2023 by W2Wizard.
@@ -25,44 +34,28 @@ echo.
25
34
echo #include " MLX42/MLX42_Int.h"
26
35
echo .
27
36
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
42
45
)
43
46
)
44
47
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
+ )
50
57
)
51
- ) ELSE (
52
- echo const char* %SHADERTYPE% _shader = " %VERSIONLINE% \n"
53
58
)
54
59
55
60
ENDLOCAL
56
61
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