// shader_factory.hpp - Helpers per crear SDL_GPUShader segons plataforma
// © 2026 JailDesigner
//
// En __APPLE__ s'utilitza MSL (Metal Shading Language) embedit com a string
// literal C++. En la resta de plataformes (Linux/Windows) s'utilitza SPIR-V
// embedit com a uint8_t[] en headers generats per CMake. La selecció és
// compile-time via #ifdef.

#pragma once

#include <SDL3/SDL_gpu.h>

#include <cstddef>
#include <cstdint>
#include <cstring>

namespace Rendering::GPU {

#ifdef __APPLE__
    inline auto createShaderMSL(SDL_GPUDevice* device,
        const char* msl_source,
        const char* entrypoint,
        SDL_GPUShaderStage stage,
        Uint32 num_samplers,
        Uint32 num_uniform_buffers) -> SDL_GPUShader* {
        SDL_GPUShaderCreateInfo info{};
        info.code = reinterpret_cast<const Uint8*>(msl_source);
        info.code_size = std::strlen(msl_source) + 1;
        info.entrypoint = entrypoint;
        info.format = SDL_GPU_SHADERFORMAT_MSL;
        info.stage = stage;
        info.num_samplers = num_samplers;
        info.num_uniform_buffers = num_uniform_buffers;
        info.num_storage_buffers = 0;
        info.num_storage_textures = 0;
        return SDL_CreateGPUShader(device, &info);
    }
#else
    inline auto createShaderSPIRV(SDL_GPUDevice* device,
        const std::uint8_t* spv_code,
        std::size_t spv_size,
        const char* entrypoint,
        SDL_GPUShaderStage stage,
        Uint32 num_samplers,
        Uint32 num_uniform_buffers) -> SDL_GPUShader* {
        SDL_GPUShaderCreateInfo info{};
        info.code = spv_code;
        info.code_size = spv_size;
        info.entrypoint = entrypoint;
        info.format = SDL_GPU_SHADERFORMAT_SPIRV;
        info.stage = stage;
        info.num_samplers = num_samplers;
        info.num_uniform_buffers = num_uniform_buffers;
        info.num_storage_buffers = 0;
        info.num_storage_textures = 0;
        return SDL_CreateGPUShader(device, &info);
    }
#endif

}  // namespace Rendering::GPU
