# t5de-renderer.exe, the 64-bit renderer process, drawing with Diligent Engine.

include(FetchContent)

# Diligent Engine's core, pinned to an exact commit. Only the Direct3D 11 backend for now; the others (Direct3D 12,
# Vulkan for ray tracing and mesh shaders, WebGPU for browsers) are switched on as they're needed.
set(DILIGENT_NO_DIRECT3D12 ON CACHE BOOL "" FORCE)
set(DILIGENT_NO_VULKAN ON CACHE BOOL "" FORCE)
set(DILIGENT_NO_OPENGL ON CACHE BOOL "" FORCE)
set(DILIGENT_NO_WEBGPU ON CACHE BOOL "" FORCE)
set(DILIGENT_NO_ARCHIVER ON CACHE BOOL "" FORCE)
set(DILIGENT_NO_SUPER_RESOLUTION ON CACHE BOOL "" FORCE)
set(DILIGENT_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(DILIGENT_INSTALL_CORE OFF CACHE BOOL "" FORCE)
FetchContent_Declare(DiligentCore
    GIT_REPOSITORY https://github.com/DiligentGraphics/DiligentCore.git
    GIT_TAG c555e4d26de3f414eaf792fa16c0c24827619b17 # master, 2026-10-27
    GIT_SUBMODULES ThirdParty/xxHash
    EXCLUDE_FROM_ALL
    SYSTEM)
FetchContent_MakeAvailable(DiligentCore)

# Shader sources, embedded in the program (Diligent compiles them at run time): each shaders/<name>.hlsl becomes
# <name>_hlsl.hpp, defining <camelCaseName>Hlsl.
function(t5de_embed_shader file name)
    set(T5DE_SHADER_FILE ${file})
    set(T5DE_SHADER_NAME ${name})
    file(READ ${CMAKE_CURRENT_SOURCE_DIR}/shaders/${file} T5DE_SHADER_SOURCE)
    get_filename_component(stem ${file} NAME_WE)
    configure_file(shaders/embed.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/generated/${stem}_hlsl.hpp @ONLY)
    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS shaders/${file})
endfunction()
t5de_embed_shader(fixed_function.hlsl fixedFunctionHlsl)

add_executable(t5de_renderer WIN32 main.cpp scene.cpp)
set_target_properties(t5de_renderer PROPERTIES OUTPUT_NAME t5de-renderer)
target_include_directories(t5de_renderer PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated)
target_link_libraries(t5de_renderer PRIVATE t5de::protocol t5de::options Diligent-GraphicsEngineD3D11-static Diligent-Common)

install(TARGETS t5de_renderer RUNTIME DESTINATION .)
