corregides les scanlines per a paletes amb fondo blanc
This commit is contained in:
55
tools/shaders/compile_spirv.cmake
Normal file
55
tools/shaders/compile_spirv.cmake
Normal file
@@ -0,0 +1,55 @@
|
||||
# compile_spirv.cmake
|
||||
# Compila shaders GLSL a SPIR-V y genera headers C++ embebibles.
|
||||
# Multiplataforma: Windows, macOS, Linux (no requiere bash, xxd ni /tmp/).
|
||||
#
|
||||
# Invocado por CMakeLists.txt con:
|
||||
# cmake -D GLSLC=<path> -D SHADERS_DIR=<path> -D HEADERS_DIR=<path> -P compile_spirv.cmake
|
||||
#
|
||||
# También puede ejecutarse manualmente desde la raíz del proyecto:
|
||||
# cmake -D GLSLC=glslc -D SHADERS_DIR=data/shaders -D HEADERS_DIR=source/core/rendering/sdl3gpu -P tools/shaders/compile_spirv.cmake
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
foreach(SHADER vert frag)
|
||||
set(SRC "${SHADERS_DIR}/postfx.${SHADER}")
|
||||
set(SPV "${HEADERS_DIR}/postfx_${SHADER}.spv")
|
||||
set(HDR "${HEADERS_DIR}/postfx_${SHADER}_spv.h")
|
||||
set(VAR "kpostfx_${SHADER}_spv")
|
||||
|
||||
message(STATUS "Compilando ${SRC} ...")
|
||||
execute_process(
|
||||
COMMAND "${GLSLC}" "${SRC}" -o "${SPV}"
|
||||
RESULT_VARIABLE GLSLC_RESULT
|
||||
ERROR_VARIABLE GLSLC_ERROR
|
||||
)
|
||||
if(NOT GLSLC_RESULT EQUAL 0)
|
||||
message(FATAL_ERROR "glslc falló para ${SRC}:\n${GLSLC_ERROR}")
|
||||
endif()
|
||||
|
||||
# Leer binario SPV como hex (sin separadores: "0302230700...")
|
||||
file(READ "${SPV}" HEX_DATA HEX)
|
||||
# Dividir en pares de caracteres hex → lista de bytes
|
||||
string(REGEX MATCHALL ".." BYTES "${HEX_DATA}")
|
||||
list(LENGTH BYTES NUM_BYTES)
|
||||
|
||||
# Construir el cuerpo del array C++ con un byte por línea
|
||||
set(ARRAY_BODY "")
|
||||
foreach(BYTE ${BYTES})
|
||||
string(APPEND ARRAY_BODY " 0x${BYTE},\n")
|
||||
endforeach()
|
||||
|
||||
file(WRITE "${HDR}"
|
||||
"#pragma once\n"
|
||||
"#include <cstddef>\n"
|
||||
"#include <cstdint>\n"
|
||||
"static const uint8_t ${VAR}[] = {\n"
|
||||
"${ARRAY_BODY}"
|
||||
"};\n"
|
||||
"static const size_t ${VAR}_size = ${NUM_BYTES};\n"
|
||||
)
|
||||
|
||||
file(REMOVE "${SPV}")
|
||||
message(STATUS " -> ${HDR} (${NUM_BYTES} bytes)")
|
||||
endforeach()
|
||||
|
||||
message(STATUS "Shaders SPIR-V compilados correctamente.")
|
||||
Reference in New Issue
Block a user