Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Atraxus committed Mar 2, 2025
1 parent 22164be commit e1fca40
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 424 deletions.
14 changes: 2 additions & 12 deletions Intern/rayx-ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if(Vulkan_FOUND)
set(GLM_DIR ../../Extern/glm/)
set(STB_DIR ../../Extern/stb/)

file(GLOB_RECURSE SOURCE ${PROJECT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE SOURCE ${PROJECT_SOURCE_DIR}/src/**.cpp)
set(IMGUI_SOURCES ${IMGUI_DIR}/backends/imgui_impl_sdl3.cpp ${IMGUI_DIR}/backends/imgui_impl_vulkan.cpp ${IMGUI_DIR}/imgui.cpp ${IMGUI_DIR}/imgui_draw.cpp ${IMGUI_DIR}/imgui_demo.cpp ${IMGUI_DIR}/imgui_tables.cpp ${IMGUI_DIR}/imgui_widgets.cpp)

add_executable(${PROJECT_NAME} ${SOURCE} ${IMGUI_SOURCES})
Expand Down Expand Up @@ -80,19 +80,9 @@ if(Vulkan_FOUND)
include(CPack)
# -----------------

# ---- GLFW Options ----
option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF)
option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF)
option(GLFW_BUILD_DOCS "Build the GLFW documentation" OFF)
option(GLFW_INSTALL "Generate installation target" OFF)
option(GLFW_DOCUMENT_INTERNALS "Include internals in documentation" OFF)
# ----------------------

# ---- Dependencies ----
target_link_libraries(${PROJECT_NAME} PRIVATE rayx-core glfw CLI11::CLI11 Vulkan::Vulkan portable_file_dialogs SDL3::SDL3)
target_link_libraries(${PROJECT_NAME} PRIVATE rayx-core CLI11::CLI11 Vulkan::Vulkan portable_file_dialogs SDL3::SDL3)
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE
${GLFW_DIR}/include
${GLFW_DIR}/deps
${IMGUI_DIR}
${IMGUI_DIR}/backends
${GLM_DIR}
Expand Down
423 changes: 200 additions & 223 deletions Intern/rayx-ui/src/Application.cpp

Large diffs are not rendered by default.

32 changes: 27 additions & 5 deletions Intern/rayx-ui/src/Application.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <optional>
#include <future>

#include "CommandParser.h"
#include "Design/DesignElement.h"
Expand All @@ -21,6 +21,9 @@ const bool enableValidationLayers = true;
class Window;
class Device;
class RenderObject;
class GridRenderSystem;
class RayRenderSystem;
class ObjectRenderSystem;
struct DesignElement;
struct DesignSource;

Expand All @@ -41,7 +44,8 @@ class Application {

void run();

enum class State { // TODO: make this private
private:
enum class State {
Initializing,
InitializeSimulation,
Simulating,
Expand All @@ -54,7 +58,6 @@ class Application {
RunningWithoutScene
} m_State{State::Initializing};

private:
// --- Order matters ---
Window m_Window; ///< Application window
CommandParser m_CommandParser; ///< Command line parser
Expand All @@ -63,21 +66,40 @@ class Application {
Simulator m_Simulator; ///< Rayx core simulator

// --- Order doesn't matter ---
std::unique_ptr<Scene> m_Scene; ///< Scene
std::unique_ptr<Scene> m_Scene; ///< Scene
std::vector<VkDescriptorSet> m_descriptorSets;
std::shared_ptr<DescriptorSetLayout> m_globalSetLayout{nullptr};
std::shared_ptr<DescriptorPool> m_GlobalDescriptorPool{nullptr}; ///< General descriptor pool
std::shared_ptr<DescriptorPool> m_TexturePool{nullptr}; ///< Descriptor pool for textures
std::shared_ptr<DescriptorSetLayout> m_textureSetLayout{nullptr};
std::shared_ptr<DescriptorPool> m_TexturePool{nullptr}; ///< Descriptor pool for textures

std::unique_ptr<GridRenderSystem> m_gridRenderSystem;
std::unique_ptr<ObjectRenderSystem> m_objectRenderSystem;
std::unique_ptr<RayRenderSystem> m_rayRenderSystem;
std::vector<std::unique_ptr<Buffer>> m_uboBuffers;

// Settings
Camera m_Camera; ///< Camera
CameraController m_CamController; ///< Camera controller
UIParameters m_UIParams; ///< UI parameters
UIHandler m_UIHandler; ///< UI render system

// Caching, Helpers, and other stuff
std::filesystem::path m_RMLPath; ///< Path to the RML file
std::unique_ptr<RAYX::Beamline> m_Beamline; ///< Beamline
RAYX::BundleHistory m_rays; ///< All rays
std::vector<std::vector<RAYX::Ray>> m_sortedRays; ///< Rays sorted by element
bool m_buildElementsNeeded = true;
bool m_buildTextureNeeded = true;
VkExtent2D sceneExtent = {1920, 1080}; // TODO: why do we need this?

// TODO: Should be in Scene
std::future<void> m_beamlineFuture;
std::future<void> m_raysFuture;
std::future<void> m_buildRayCacheFuture;
std::future<std::vector<Scene::RenderObjectInput>> m_getRObjInputsFuture;
// TODO: Should be in Simulator
std::future<void> m_simulationFuture;

void init();

Expand Down
2 changes: 1 addition & 1 deletion Intern/rayx-ui/src/Camera.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Camera.h"

#include <imgui_impl_glfw.h>
#include <imgui_impl_sdl3.h>
#include <imgui_impl_vulkan.h>

#include <fstream>
Expand Down
18 changes: 14 additions & 4 deletions Intern/rayx-ui/src/CommandParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <cstring>

#include "Debug/Debug.h"
#include "Debug/Instrumentor.h"

CommandParser::CommandParser(int _argc, char* const* _argv) : m_cli11{std::make_shared<CLI::App>("for rayx-ui CLI")} {
for (const std::pair<char, Options> option : m_ParserCommands) {
// Full name string
Expand Down Expand Up @@ -32,13 +35,20 @@ CommandParser::CommandParser(int _argc, char* const* _argv) : m_cli11{std::make_
try {
m_cli11->parse(_argc, _argv);
} catch (const CLI::ParseError& e) {
m_cli11_return = m_cli11->exit(e);
int result = m_cli11->exit(e);
if ((e.get_name() == "CallForHelp") || (e.get_name() == "CallForAllHelp"))
exit(1);
else
std::cout << "CLI ERROR" << m_cli11_return << " " << e.get_name();
std::cout << "CLI ERROR" << result << " " << e.get_name();
exit(1);
}
}

void CommandParser::analyzeCommands() const {}
if (m_args.m_verbose) {
RAYX::setDebugVerbose(true);
RAYX_VERB << "Verbose logging enabled.";
}
if (m_args.m_benchmark) {
RAYX_VERB << "Starting in Benchmark Mode.\n";
RAYX::BENCH_FLAG = true;
}
}
9 changes: 0 additions & 9 deletions Intern/rayx-ui/src/CommandParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@

class CommandParser {
public:
// Default constructor
CommandParser() = default;
// Custom constructor
CommandParser(int _argc, char* const* _argv);

~CommandParser() = default;

/**
* @brief Set command restrictions here (for ex int intervals etc.)
*
*/
void analyzeCommands() const;

std::shared_ptr<CLI::App> m_cli11;
// CLI Arguments
// Flags initialize to DISABLED
Expand All @@ -30,7 +22,6 @@ class CommandParser {
} m_args;

private:
int m_cli11_return;
enum OptionType { BOOL, INT, STRING, BOOL_STRING, OPTIONAL_INT };
struct Options {
// CLI::Option cli11_option;
Expand Down
9 changes: 5 additions & 4 deletions Intern/rayx-ui/src/GraphicsCore/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <set>
#include <unordered_set>

#include <SDL3/SDL_vulkan.h>

#include "Debug/Debug.h"

// local callback functions (needs to have this signature to be passed to vulkan)
Expand Down Expand Up @@ -257,11 +259,10 @@ bool Device::checkValidationLayerSupport() const {
}

std::vector<const char*> Device::getRequiredExtensions() const {
uint32_t glfwExtensionCount = 0;
const char** glfwExtensions;
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
uint32_t sdl3ExtensionCount = 0;
auto sdl3Extensions = SDL_Vulkan_GetInstanceExtensions(&sdl3ExtensionCount);

std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
std::vector<const char*> extensions(sdl3Extensions, sdl3Extensions + sdl3ExtensionCount);

if (enableValidationLayers) {
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
Expand Down
7 changes: 1 addition & 6 deletions Intern/rayx-ui/src/GraphicsCore/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ Renderer::~Renderer() {

void Renderer::recreateSwapChain() {
int width = 0, height = 0;
glfwGetFramebufferSize(m_Window.window(), &width, &height);
while (width == 0 || height == 0) {
glfwGetFramebufferSize(m_Window.window(), &width, &height);
glfwWaitEvents();
}
vkDeviceWaitIdle(m_Device.device());
SDL_GetWindowSize(m_Window.window(), &width, &height);

if (m_SwapChain == nullptr) {
m_SwapChain = std::make_unique<SwapChain>(m_Device, VkExtent2D(width, height));
Expand Down
24 changes: 10 additions & 14 deletions Intern/rayx-ui/src/GraphicsCore/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Window.h"

#include <stdexcept>
#include <SDL3/SDL_vulkan.h>

#include "Debug/Debug.h"

Expand All @@ -19,28 +20,23 @@ Window::Window(uint32_t width, uint32_t height, const char* title) {
m_height = height;
m_title = title;

glfwInit();
SDL_Init(SDL_INIT_VIDEO);

glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

m_Window = glfwCreateWindow(m_width, m_height, m_title, nullptr, nullptr);
glfwSetWindowUserPointer(m_Window, this);
glfwSetFramebufferSizeCallback(m_Window, framebufferResizeCallback);
m_Window = SDL_CreateWindow(title, width, height, SDL_WINDOW_VULKAN);
// glfwSetWindowUserPointer(m_Window, this);
// glfwSetFramebufferSizeCallback(m_Window, framebufferResizeCallback);
}

Window::~Window() {
glfwDestroyWindow(m_Window);
glfwTerminate();
}
Window::~Window() { SDL_Quit(); }

/**
* Callback function for when the framebuffer is resized. Sets the framebufferResized flag to true.
* Resizes the window to the new framebuffer size.
*/
void Window::framebufferResizeCallback(GLFWwindow* rawWindow, int width, int height) {
auto window = reinterpret_cast<Window*>(glfwGetWindowUserPointer(rawWindow));
void Window::framebufferResizeCallback(SDL_Window* rawWindow, int width, int height) {
auto window = reinterpret_cast<Window*>(rawWindow); // TODO: This...
if (window) {
window->onFramebufferResize(width, height);
window->onFramebufferResize(width, height); // TODO: and this is pretty weird
} else {
RAYX_EXIT << "Failed to get window pointer in framebuffer resize callback!";
}
Expand All @@ -56,7 +52,7 @@ void Window::onFramebufferResize(int width, int height) {
* Creates a Vulkan surface associated with the window.
*/
void Window::createSurface(VkInstance instance, VkSurfaceKHR* surface) {
if (glfwCreateWindowSurface(instance, m_Window, nullptr, surface) != VK_SUCCESS) {
if (!SDL_Vulkan_CreateSurface(m_Window, instance, nullptr, surface)) {
throw std::runtime_error("failed to create window surface!");
}
}
14 changes: 6 additions & 8 deletions Intern/rayx-ui/src/GraphicsCore/Window.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#define GLFW_INCLUDE_VULKAN
#include "GLFW/glfw3.h"
#include <SDL3/SDL.h>

#include <vulkan/vulkan.hpp>

struct [[maybe_unused]] Extent2D {
uint32_t width;
Expand Down Expand Up @@ -41,12 +42,9 @@ class Window {
*/
void createSurface(VkInstance instance, VkSurfaceKHR* surface);

GLFWwindow* window() const { return m_Window; }
SDL_Window* window() const { return m_Window; }
VkExtent2D getExtent() const { return {m_width, m_height}; }

bool shouldClose() const { return glfwWindowShouldClose(m_Window); }
bool isMinimized() const { return glfwGetWindowAttrib(m_Window, GLFW_ICONIFIED); }

bool wasWindowResized() { return m_framebufferResized; }
void resetWindowResizedFlag() { m_framebufferResized = false; }

Expand All @@ -57,13 +55,13 @@ class Window {
* @param width The new width of the framebuffer.
* @param height The new height of the framebuffer.
*/
static void framebufferResizeCallback(GLFWwindow* rawWindow, int width, int height);
static void framebufferResizeCallback(SDL_Window* rawWindow, int width, int height);
void onFramebufferResize(int width, int height);

uint32_t m_width;
uint32_t m_height;
bool m_framebufferResized = false;
const char* m_title;

GLFWwindow* m_Window;
SDL_Window* m_Window;
};
2 changes: 1 addition & 1 deletion Intern/rayx-ui/src/RayProcessing.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "RayProcessing.h"

#include <imgui_impl_glfw.h>
#include <imgui_impl_sdl3.h>
#include <imgui_impl_vulkan.h>

#include <algorithm>
Expand Down
Loading

0 comments on commit e1fca40

Please sign in to comment.