Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempted to run on macos #415

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Resources/Shaders/infinite_grid.frag
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main()
{
vec2 dudv = vec2(length(vec2(dFdx(uv.x), dFdy(uv.x))), length(vec2(dFdx(uv.y), dFdy(uv.y))));

float lodLevel = max(0.0, log10((length(dudv) * gridMinPixelsBetweenCells) / gridCellSize) + 1.0);
float lodLevel = max(0.0, log_10((length(dudv) * gridMinPixelsBetweenCells) / gridCellSize) + 1.0);
float lodFade = fract(lodLevel);

float lod0 = gridCellSize * pow(10.0, floor(lodLevel + 0));
Expand Down
2 changes: 1 addition & 1 deletion Resources/Shaders/utility.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
float log10(float x)
float log_10(float x)
{
return log(x) / log(10.0);
}
Expand Down
7 changes: 5 additions & 2 deletions Tetragrama/Components/LogUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ namespace Tetragrama::Components
{
LogUIComponent::LogUIComponent(std::string_view name, bool visibility) : UIComponent(name, visibility, false)
{
Logger::AddEventHandler(std::bind(&LogUIComponent::OnLog, this, std::placeholders::_1));
auto m_cookie = Logger::AddEventHandler(std::bind(&LogUIComponent::OnLog, this, std::placeholders::_1));
}

LogUIComponent::~LogUIComponent() {}
LogUIComponent::~LogUIComponent()
{
Logger::RemoveEventHandler(m_cookie);
}

void LogUIComponent::Update(ZEngine::Core::TimeStep dt) {}

Expand Down
1 change: 1 addition & 0 deletions Tetragrama/Components/LogUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Tetragrama::Components
std::string GetMessageType(const ZEngine::Logging::LogMessage& message);

private:
uint32_t m_cookie{0};
uint32_t m_maxCount{1024};
uint32_t m_currentCount{0};
bool m_auto_scroll{true};
Expand Down
9 changes: 5 additions & 4 deletions ZEngine/ZEngine/Hardwares/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ namespace ZEngine::Hardwares
/*Create Vulkan Instance*/
VkApplicationInfo app_info = {.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .pNext = VK_NULL_HANDLE, .pApplicationName = ApplicationName.data(), .applicationVersion = 1, .pEngineName = EngineName.data(), .engineVersion = 1, .apiVersion = VK_API_VERSION_1_3};

VkInstanceCreateInfo instance_create_info = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pNext = VK_NULL_HANDLE, .flags = 0, .pApplicationInfo = &app_info};
VkInstanceCreateInfo instance_create_info = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pNext = VK_NULL_HANDLE, .flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR, .pApplicationInfo = &app_info};

auto layer_properties = m_layer.GetInstanceLayerProperties();

std::vector<const char*> enabled_layer_name_collection;
std::vector<LayerProperty> selected_layer_property_collection;

#ifdef ENABLE_VULKAN_VALIDATION_LAYER
std::unordered_set<std::string> validation_layer_name_collection = {"VK_LAYER_LUNARG_api_dump", "VK_LAYER_KHRONOS_validation", "VK_LAYER_LUNARG_monitor", "VK_LAYER_LUNARG_screenshot"};
std::unordered_set<std::string> validation_layer_name_collection = {"VK_LAYER_LUNARG_api_dump", "VK_LAYER_KHRONOS_validation", "VK_LAYER_LUNAR_monitor"};

for (std::string_view layer_name : validation_layer_name_collection)
{
Expand Down Expand Up @@ -91,6 +91,7 @@ namespace ZEngine::Hardwares
}
}

enabled_extension_layer_name_collection.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
instance_create_info.enabledLayerCount = enabled_layer_name_collection.size();
instance_create_info.ppEnabledLayerNames = enabled_layer_name_collection.data();
instance_create_info.enabledExtensionCount = enabled_extension_layer_name_collection.size();
Expand Down Expand Up @@ -144,7 +145,7 @@ namespace ZEngine::Hardwares
vkGetPhysicalDeviceProperties(physical_device, &physical_device_properties);
vkGetPhysicalDeviceFeatures(physical_device, &physical_device_feature);

if ((physical_device_feature.geometryShader == VK_TRUE) && (physical_device_feature.samplerAnisotropy == VK_TRUE) && ((physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) || (physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)))
if ((physical_device_feature.samplerAnisotropy == VK_TRUE) && ((physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) || (physical_device_properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)))
{
PhysicalDevice = physical_device;
PhysicalDeviceProperties = physical_device_properties;
Expand All @@ -155,7 +156,7 @@ namespace ZEngine::Hardwares
}

std::vector<const char*> requested_device_enabled_layer_name_collection = {};
std::vector<const char*> requested_device_extension_layer_name_collection = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME};
std::vector<const char*> requested_device_extension_layer_name_collection = {VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, "VK_KHR_portability_subset"};

for (LayerProperty& layer : selected_layer_property_collection)
{
Expand Down
29 changes: 18 additions & 11 deletions ZEngine/ZEngine/Logging/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

namespace ZEngine::Logging
{
static std::atomic_uint32_t g_cookie = 0;
spdlog::sink_ptr Logger::s_sink = nullptr;
std::recursive_mutex Logger::s_mutex = {};
std::vector<std::shared_ptr<spdlog::logger>> Logger::s_logger_collection = {};
std::vector<std::pair<uint32_t, Logger::LogEventHandler>> Logger::s_log_event_handlers = {};
static std::atomic_uint32_t g_cookie = 0;
spdlog::sink_ptr Logger::s_sink = nullptr;
std::recursive_mutex Logger::s_mutex = {};
std::vector<std::shared_ptr<spdlog::logger>> Logger::s_logger_collection = {};
std::map<uint32_t, Logger::LogEventHandler> Logger::s_log_event_handlers = {};

void Logger::Initialize(const LoggerConfiguration& configuration)
void Logger::Initialize(const LoggerConfiguration& configuration)
{
const auto current_directoy = std::filesystem::current_path();
const auto log_directory = fmt::format("{0}/{1}", current_directoy.string(), configuration.OutputDirectory);
Expand Down Expand Up @@ -53,16 +53,23 @@ namespace ZEngine::Logging
void Logger::Dispose()
{
s_log_event_handlers.clear();
s_log_event_handlers.shrink_to_fit();

Flush();

s_logger_collection.clear();
s_logger_collection.shrink_to_fit();
}

void Logger::AddEventHandler(LogEventHandler handler)
uint32_t Logger::AddEventHandler(LogEventHandler handler)
{
s_log_event_handlers.emplace_back(g_cookie++, handler);
std::unique_lock l(s_mutex);
uint32_t cookie = g_cookie++;
s_log_event_handlers[cookie] = handler;
return cookie;
}

void Logger::RemoveEventHandler(uint32_t cookie)
{
std::unique_lock l(s_mutex);
s_log_event_handlers.erase(cookie);
}

} // namespace ZEngine::Logging
29 changes: 15 additions & 14 deletions ZEngine/ZEngine/Logging/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,26 @@ namespace ZEngine::Logging
{
using LogEventHandler = std::function<void(LogMessage)>;

static void Initialize(const LoggerConfiguration&);
static void Flush();
static void Dispose();
static void AddEventHandler(LogEventHandler handler);

static void Info(std::string msg);
static void Trace(std::string msg);
static void Warn(std::string msg);
static void Error(std::string msg);
static void Critical(std::string msg);
static void Initialize(const LoggerConfiguration&);
static void Flush();
static void Dispose();
static uint32_t AddEventHandler(LogEventHandler handler);
static void RemoveEventHandler(uint32_t cookie);

static void Info(std::string msg);
static void Trace(std::string msg);
static void Warn(std::string msg);
static void Error(std::string msg);
static void Critical(std::string msg);

private:
Logger() = delete;
Logger(const Logger&) = delete;

static spdlog::sink_ptr s_sink;
static std::recursive_mutex s_mutex;
static std::vector<std::shared_ptr<spdlog::logger>> s_logger_collection;
static std::vector<std::pair<uint32_t, LogEventHandler>> s_log_event_handlers;
static spdlog::sink_ptr s_sink;
static std::recursive_mutex s_mutex;
static std::vector<std::shared_ptr<spdlog::logger>> s_logger_collection;
static std::map<uint32_t, LogEventHandler> s_log_event_handlers;
};

inline void Logger::Info(std::string msg)
Expand Down
4 changes: 2 additions & 2 deletions ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ namespace ZEngine::Rendering::Renderers
RenderGraph->AddCallbackPass("Depth Pre-Pass", scene_depth_prepass);
RenderGraph->AddCallbackPass("Skybox Pass", skybox_pass);
RenderGraph->AddCallbackPass("Grid Pass", grid_pass);
RenderGraph->AddCallbackPass("G-Buffer Pass", gbuffer_pass);
RenderGraph->AddCallbackPass("Lighting Pass", lighting_pass);
// RenderGraph->AddCallbackPass("G-Buffer Pass", gbuffer_pass);
// RenderGraph->AddCallbackPass("Lighting Pass", lighting_pass);

RenderGraph->Setup();
RenderGraph->Compile();
Expand Down
7 changes: 2 additions & 5 deletions ZEngine/ZEngine/Rendering/Renderers/ImGUIRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ namespace ZEngine::Rendering::Renderers
style.ChildBorderSize = 0.f;
style.FrameRounding = 7.0f;

auto window_property = current_window->GetWindowProperty();
io.Fonts->AddFontFromFileTTF("Settings/Fonts/OpenSans/OpenSans-Bold.ttf", 17.f * window_property.DpiScale);
io.FontDefault = io.Fonts->AddFontFromFileTTF("Settings/Fonts/OpenSans/OpenSans-Regular.ttf", 17.f * window_property.DpiScale);
io.FontGlobalScale = window_property.DpiScale;
io.FontDefault = io.Fonts->AddFontFromFileTTF("Settings/Fonts/OpenSans/OpenSans-Regular.ttf", 13.0f);

ImGui_ImplGlfw_InitForVulkan(reinterpret_cast<GLFWwindow*>(current_window->GetNativeWindow()), false);

Expand Down Expand Up @@ -344,4 +341,4 @@ namespace ZEngine::Rendering::Renderers

return m_frame_output;
}
} // namespace ZEngine::Rendering::Renderers
} // namespace ZEngine::Rendering::Renderers