arreglos en make i cmake per estandaritzar amb la resta de projectes
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,85 +0,0 @@
|
||||
# Makefile para herramientas de Coffee Crisis Arcade Edition
|
||||
# =========================================================
|
||||
|
||||
# Variables
|
||||
CXX := g++
|
||||
CXXFLAGS := -std=c++20 -Wall -Os -I../../source
|
||||
SOURCES := pack_resources.cpp ../../source/core/resources/resource_pack.cpp
|
||||
TARGET := pack_resources
|
||||
CLEAN_FILES := pack_resources *.pack *.o
|
||||
|
||||
# Detectar sistema operativo
|
||||
ifeq ($(OS),Windows_NT)
|
||||
DETECTED_OS := Windows
|
||||
TARGET := $(TARGET).exe
|
||||
CLEAN_CMD := del /Q
|
||||
FixPath = $(subst /,\\,$1)
|
||||
else
|
||||
DETECTED_OS := $(shell uname -s)
|
||||
CLEAN_CMD := rm -f
|
||||
FixPath = $1
|
||||
endif
|
||||
|
||||
# Reglas principales
|
||||
.PHONY: all pack_tool pack clean help test_pack
|
||||
|
||||
# Compilar herramienta de empaquetado
|
||||
all: pack_tool
|
||||
|
||||
pack_tool:
|
||||
@echo "Compilando herramienta de empaquetado para $(DETECTED_OS)..."
|
||||
$(CXX) $(CXXFLAGS) $(SOURCES) -o $(TARGET)
|
||||
@echo "✓ Herramienta compilada: $(TARGET)"
|
||||
|
||||
# Limpiar archivos generados
|
||||
clean:
|
||||
@echo "Limpiando archivos generados..."
|
||||
$(CLEAN_CMD) $(call FixPath,$(CLEAN_FILES))
|
||||
@echo "✓ Archivos limpiados"
|
||||
|
||||
# Crear pack de recursos final (invocado desde Makefile raíz)
|
||||
pack: pack_tool
|
||||
ifeq ($(OS),Windows_NT)
|
||||
.\$(TARGET) ..\..\data ..\..\resources.pack
|
||||
else
|
||||
./$(TARGET) ../../data ../../resources.pack
|
||||
endif
|
||||
|
||||
# Crear pack de recursos de prueba
|
||||
test_pack: pack_tool
|
||||
@echo "Creando pack de recursos de prueba..."
|
||||
ifeq ($(OS),Windows_NT)
|
||||
.\$(TARGET) ..\..\data test_resources.pack
|
||||
else
|
||||
./$(TARGET) ../../data test_resources.pack
|
||||
endif
|
||||
@echo "✓ Pack de prueba creado: test_resources.pack"
|
||||
|
||||
# Crear pack de recursos final
|
||||
create_pack: pack_tool
|
||||
@echo "Creando pack de recursos final..."
|
||||
ifeq ($(OS),Windows_NT)
|
||||
.\$(TARGET) ..\..\data ..\..\resources.pack
|
||||
else
|
||||
./$(TARGET) ../../data ../../resources.pack
|
||||
endif
|
||||
@echo "✓ Pack final creado: ../../resources.pack"
|
||||
|
||||
# Mostrar ayuda
|
||||
help:
|
||||
@echo "Makefile para herramientas de Coffee Crisis Arcade Edition"
|
||||
@echo "========================================================="
|
||||
@echo ""
|
||||
@echo "Comandos disponibles:"
|
||||
@echo " all - Compilar herramienta de empaquetado (por defecto)"
|
||||
@echo " pack_tool - Compilar herramienta de empaquetado"
|
||||
@echo " test_pack - Crear pack de recursos de prueba"
|
||||
@echo " create_pack - Crear pack de recursos final"
|
||||
@echo " clean - Limpiar archivos generados"
|
||||
@echo " help - Mostrar esta ayuda"
|
||||
@echo ""
|
||||
@echo "Ejemplos de uso:"
|
||||
@echo " make # Compilar herramienta"
|
||||
@echo " make test_pack # Crear pack de prueba"
|
||||
@echo " make create_pack # Crear pack final"
|
||||
@echo " make clean # Limpiar archivos"
|
||||
101
tools/shaders/compile_spirv.cmake
Normal file
101
tools/shaders/compile_spirv.cmake
Normal file
@@ -0,0 +1,101 @@
|
||||
# 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)
|
||||
cmake_policy(SET CMP0007 NEW)
|
||||
|
||||
# Lista de shaders: fuente relativa a SHADERS_DIR
|
||||
set(SHADER_SOURCES
|
||||
"postfx.vert"
|
||||
"postfx.frag"
|
||||
"upscale.frag"
|
||||
"downscale.frag"
|
||||
"crtpi_frag.glsl"
|
||||
)
|
||||
|
||||
# Nombre de la variable C++ para cada shader (mismo orden)
|
||||
set(SHADER_VARS
|
||||
"kpostfx_vert_spv"
|
||||
"kpostfx_frag_spv"
|
||||
"kupscale_frag_spv"
|
||||
"kdownscale_frag_spv"
|
||||
"kcrtpi_frag_spv"
|
||||
)
|
||||
|
||||
# Flags extra de glslc para cada shader (vacío si no hay)
|
||||
set(SHADER_FLAGS
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
||||
"-fshader-stage=frag"
|
||||
)
|
||||
|
||||
list(LENGTH SHADER_SOURCES NUM_SHADERS)
|
||||
math(EXPR LAST_IDX "${NUM_SHADERS} - 1")
|
||||
|
||||
foreach(IDX RANGE ${LAST_IDX})
|
||||
list(GET SHADER_SOURCES ${IDX} SRC_NAME)
|
||||
list(GET SHADER_VARS ${IDX} VAR)
|
||||
list(GET SHADER_FLAGS ${IDX} EXTRA_FLAG)
|
||||
|
||||
# Derivar nombre del header desde la variable: kpostfx_vert_spv → postfx_vert_spv.h
|
||||
string(REGEX REPLACE "^k" "" HDR_BASE "${VAR}")
|
||||
set(SRC "${SHADERS_DIR}/${SRC_NAME}")
|
||||
set(SPV "${HEADERS_DIR}/${HDR_BASE}.spv")
|
||||
set(HDR "${HEADERS_DIR}/${HDR_BASE}.h")
|
||||
|
||||
message(STATUS "Compilando ${SRC} ...")
|
||||
|
||||
if(EXTRA_FLAG)
|
||||
execute_process(
|
||||
COMMAND "${GLSLC}" "${EXTRA_FLAG}" "${SRC}" -o "${SPV}"
|
||||
RESULT_VARIABLE GLSLC_RESULT
|
||||
ERROR_VARIABLE GLSLC_ERROR
|
||||
)
|
||||
else()
|
||||
execute_process(
|
||||
COMMAND "${GLSLC}" "${SRC}" -o "${SPV}"
|
||||
RESULT_VARIABLE GLSLC_RESULT
|
||||
ERROR_VARIABLE GLSLC_ERROR
|
||||
)
|
||||
endif()
|
||||
|
||||
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.")
|
||||
@@ -1,65 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Compile Vulkan GLSL shaders to SPIR-V and update the C++ headers used by SDL3GPUShader.
|
||||
# Required: glslc (from Vulkan SDK or: brew install glslang / apt install glslang-tools)
|
||||
#
|
||||
# Run from the project root: tools/shaders/compile_spirv.sh
|
||||
|
||||
set -e
|
||||
|
||||
SHADERS_DIR="data/shaders"
|
||||
HEADERS_DIR="source/core/rendering/sdl3gpu"
|
||||
|
||||
if ! command -v glslc &> /dev/null; then
|
||||
echo "ERROR: glslc not found. Install Vulkan SDK or run:"
|
||||
echo " macOS: brew install glslang"
|
||||
echo " Linux: sudo apt install glslang-tools"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Compiling SPIR-V shaders..."
|
||||
|
||||
glslc "${SHADERS_DIR}/postfx.vert" -o /tmp/postfx.vert.spv
|
||||
glslc "${SHADERS_DIR}/postfx.frag" -o /tmp/postfx.frag.spv
|
||||
glslc -fshader-stage=fragment "${SHADERS_DIR}/crtpi_frag.glsl" -o /tmp/crtpi_frag.spv
|
||||
glslc "${SHADERS_DIR}/upscale.frag" -o /tmp/upscale.frag.spv
|
||||
glslc "${SHADERS_DIR}/downscale.frag" -o /tmp/downscale.frag.spv
|
||||
|
||||
echo "Generating C++ headers..."
|
||||
|
||||
xxd -i /tmp/postfx.vert.spv | \
|
||||
sed 's/unsigned char .*postfx_vert_spv\[\]/static const uint8_t kpostfx_vert_spv[]/' | \
|
||||
sed 's/unsigned int .*postfx_vert_spv_len/static const size_t kpostfx_vert_spv_size/' \
|
||||
> "${HEADERS_DIR}/postfx_vert_spv.h"
|
||||
|
||||
xxd -i /tmp/postfx.frag.spv | \
|
||||
sed 's/unsigned char .*postfx_frag_spv\[\]/static const uint8_t kpostfx_frag_spv[]/' | \
|
||||
sed 's/unsigned int .*postfx_frag_spv_len/static const size_t kpostfx_frag_spv_size/' \
|
||||
> "${HEADERS_DIR}/postfx_frag_spv.h"
|
||||
|
||||
xxd -i /tmp/crtpi_frag.spv | \
|
||||
sed 's/unsigned char .*crtpi_frag_spv\[\]/static const uint8_t kcrtpi_frag_spv[]/' | \
|
||||
sed 's/unsigned int .*crtpi_frag_spv_len/static const size_t kcrtpi_frag_spv_size/' \
|
||||
> "${HEADERS_DIR}/crtpi_frag_spv.h"
|
||||
|
||||
xxd -i /tmp/upscale.frag.spv | \
|
||||
sed 's/unsigned char .*upscale_frag_spv\[\]/static const uint8_t kupscale_frag_spv[]/' | \
|
||||
sed 's/unsigned int .*upscale_frag_spv_len/static const size_t kupscale_frag_spv_size/' \
|
||||
> "${HEADERS_DIR}/upscale_frag_spv.h"
|
||||
|
||||
xxd -i /tmp/downscale.frag.spv | \
|
||||
sed 's/unsigned char .*downscale_frag_spv\[\]/static const uint8_t kdownscale_frag_spv[]/' | \
|
||||
sed 's/unsigned int .*downscale_frag_spv_len/static const size_t kdownscale_frag_spv_size/' \
|
||||
> "${HEADERS_DIR}/downscale_frag_spv.h"
|
||||
|
||||
# Prepend required includes to the headers
|
||||
for f in "${HEADERS_DIR}/postfx_vert_spv.h" "${HEADERS_DIR}/postfx_frag_spv.h" "${HEADERS_DIR}/crtpi_frag_spv.h" "${HEADERS_DIR}/upscale_frag_spv.h" "${HEADERS_DIR}/downscale_frag_spv.h"; do
|
||||
echo -e "#pragma once\n#include <cstdint>\n#include <cstddef>\n$(cat "$f")" > "$f"
|
||||
done
|
||||
|
||||
echo "Done. Headers updated in ${HEADERS_DIR}/"
|
||||
echo " postfx_vert_spv.h"
|
||||
echo " postfx_frag_spv.h"
|
||||
echo " crtpi_frag_spv.h"
|
||||
echo " upscale_frag_spv.h"
|
||||
echo " downscale_frag_spv.h"
|
||||
echo "Rebuild the project to use the new shaders."
|
||||
Reference in New Issue
Block a user