#!/bin/bash
set -eu

# glslc
glsl_compile="glslc"
glsl_flags="--target-spv=spv1.6 -std=460"
glsl_stage_vert="-fshader-stage=vert"
glsl_stage_frag="-fshader-stage=frag"
glsl_stage_tesc="-fshader-stage=tesc"
glsl_stage_tese="-fshader-stage=tese"
glsl_stage_geom="-fshader-stage=geom"
glsl_stage_comp="-fshader-stage=comp"
glsl_out="-o./assets/shaders/"

# SPIR-V
mkdir -p ./assets/shaders

for file in ./src/shaders/*.glsl; do
	base_name=$(basename -- "$file" .glsl)

	case "$base_name" in 
		*.vert) glsl_stage="${glsl_stage_vert}" ;;
		*.frag) glsl_stage="${glsl_stage_frag}" ;;
		*.tesc) glsl_stage="${glsl_stage_tesc}" ;;
		*.tese) glsl_stage="${glsl_stage_tese}" ;;
		*.geom) glsl_stage="${glsl_stage_geom}" ;;
		*.comp) glsl_stage="${glsl_stage_comp}" ;;
		*) continue ;;
	esac

	$glsl_compile $glsl_flags $glsl_stage $file "${glsl_out}${base_name}.spv"
done
