Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Template

This is no code capable of running on its own, look to foray-examples if you need that. This is instead just a simple template

Header

#pragma once
#include <foray_api.hpp>
namespace foray-template {
class TemplateApp : public foray::base::DefaultAppBase //
{
protected:
virtual void ApiInit() override; // Load the scene and configure render stages
virtual void ApiOnEvent(const foray::osi::Event* event) override; // Send OS events to active scene
virtual void ApiOnResized(VkExtent2D size) override; // Send resize event to active scene (to update aspect ratio of camera projection matrix)
virtual void ApiRender(foray::base::FrameRenderInfo& renderInfo) override; // Record our frame onto the command buffer
virtual void ApiDestroy() override; // Destroy any allocated
// TODO: Add additional render stages
foray::stages::ImageToSwapchainStage mSwapCopyStage; // Copies a frame buffer to the swapchain
std::unique_ptr<foray::scene::Scene> mScene;
};
} // namespace foray-template
Intended as base class for demo applications. Compared to MinimalAppBase it offers a complete simple ...
Definition foray_defaultappbase.hpp:20
Context used for render processes. This object is rebuilt for every frame. /.
Definition foray_framerenderinfo.hpp:14
Base class for operating system events.
Definition foray_event.hpp:13
The only purpose of this class is to copy the image onto the swapchain.
Definition foray_imagetoswapchain.hpp:7
Definition foray_api.hpp:19

Source

void TemplateApp::ApiInit()
{
// Load scene
mScene = std::make_unique<foray::scene::Scene>(&mContext);
foray::gltf::ModelConverter converter(mScene.get());
converter.LoadGltfModel(
// TODO: Add path to glTF file to load
);
// Initialize TLAS
mScene->UpdateTlasManager();
// Adds a node with camera + freeflight controls
mScene->UseDefaultCamera(true);
// Initialize and configure stages
// TODO: Configure your stages
foray::core::ManagedImage* mainFrameBuf = nullptr; // TODO: set main frame buffer
mSwapCopyStage.Init(&mContext, mainFrameBuf);
mSwapCopyStage.SetFlipY(true); // Flip viewport since scene is loaded as +Y = up, but Vulkan uses -Y = up
// TODO: Register your stages so they receive the resize, os event and shader compile callbacks
RegisterRenderStage(&mSwapCopyStage);
}
void TemplateApp::ApiOnEvent(const foray::osi::Event* event)
{
mScene->InvokeOnEvent(event);
}
void TemplateApp::ApiOnResized(VkExtent2D size)
{
mScene->InvokeOnResized(size);
}
void TemplateApp::ApiRender(foray::base::FrameRenderInfo& renderInfo)
{
// Get and begin command buffer
cmdBuffer.Begin();
// Update scene (uploads scene specific dynamic data such as node transformations, camera matrices, ...)
mScene->Update(renderInfo, cmdBuffer);
// TODO: Record frames
// Copy ray tracing output to swapchain
mSwapCopyStage.RecordFrame(cmdBuffer, renderInfo);
// Prepare swapchain image for present and submit command buffer
renderInfo.GetInFlightFrame()->PrepareSwapchainImageForPresent(cmdBuffer, renderInfo.GetImageLayoutCache());
cmdBuffer.Submit();
}
void TemplateApp::ApiDestroy()
{
mSwapCopyStage.Destroy();
mScene = nullptr;
}
void PrepareSwapchainImageForPresent(VkCommandBuffer cmdBuffer)
Adds a Pipeline barrier transitioning the swapchain image into present layout and assuring all writes...
Definition foray_framerenderinfo.hpp:35
core::DeviceSyncCommandBuffer & GetPrimaryCommandBuffer()
Definition foray_framerenderinfo.hpp:26
virtual void Begin()
vkBeginCommandBuffer();
Extension of the commandbuffer wrapper for device and/or host synchronized command buffer execution.
Definition foray_commandbuffer.hpp:90
virtual void Submit()
Submits the commandbuffer.
Wraps allocation and lifetime functionality of VkImage.
Definition foray_managedimage.hpp:13
Type which reads glTF files and merges a scene of the file into the scene graph.
Definition foray_modelconverter.hpp:37

CMakeLists.txt

project(template) // TODO: Name your project
# collect sources
file(GLOB_RECURSE src "*.cpp")
# Make sure there are source files, add_executable would otherwise fail
if (NOT src)
message(FATAL_ERROR "Project \"${PROJECT_NAME}\" does not contain any source files")
endif ()
# Declare executable
add_executable(${PROJECT_NAME} ${src})
# Set strict mode for project only
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS ${STRICT_FLAGS})
# Set directories via compile macros
target_compile_options(${PROJECT_NAME} PUBLIC "-DFORAY_SHADER_DIR=\"$CACHE{FORAY_SHADER_DIR}\"")
# Link foray lib
target_link_libraries(
${PROJECT_NAME}
PUBLIC foray
)
# Windows requires SDL2 libs linked specifically
if (WIN32)
target_link_libraries(
${PROJECT_NAME}
PUBLIC ${SDL2_LIBRARIES}
)
endif()
# Configure include directories
target_include_directories(
${PROJECT_NAME}
PUBLIC "${CMAKE_SOURCE_DIR}/foray/src"
PUBLIC "${CMAKE_SOURCE_DIR}/foray/third_party"
PUBLIC ${Vulkan_INCLUDE_DIR}
)