Archived
1
Fork 0

Use fetch content on macOS for SPIRV-Cross, and fix compilation using the new Windows changes

This commit is contained in:
redstrate 2020-08-14 19:56:27 -04:00
parent c42bde8830
commit 0e008a1beb
8 changed files with 29 additions and 43 deletions

View file

@ -14,16 +14,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/Common.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cmake/AddPlatformExecutable.cmake) include(${CMAKE_CURRENT_LIST_DIR}/cmake/AddPlatformExecutable.cmake)
include(FetchContent) include(FetchContent)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND NOT IOS)
message("macOS build detected!")
set(ENABLE_METAL TRUE)
set(ENABLE_DARWIN TRUE)
set(ENABLE_MACOS TRUE)
set(CMAKE_XCODE_GENERATE_SCHEME OFF)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
message("Linux build detected!") message("Linux build detected!")
@ -83,6 +73,18 @@ macro(manual_download)
set(CMAKE_FOLDER "") set(CMAKE_FOLDER "")
endmacro() endmacro()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND NOT IOS)
message("macOS build detected!")
set(ENABLE_METAL TRUE)
set(ENABLE_DARWIN TRUE)
set(ENABLE_MACOS TRUE)
set(CMAKE_XCODE_GENERATE_SCHEME OFF)
manual_download()
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS") if(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
message("iOS build detected!") message("iOS build detected!")
@ -120,7 +122,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
manual_download() manual_download()
endif() endif()
if(NOT ENABLE_IOS AND NOT ENABLE_TVOS AND NOT ENABLE_WINDOWS) if(NOT TARGET spirv-cross-cpp)
find_package(spirv_cross_core REQUIRED) find_package(spirv_cross_core REQUIRED)
find_package(spirv_cross_glsl REQUIRED) find_package(spirv_cross_glsl REQUIRED)
find_package(spirv_cross_cpp REQUIRED) find_package(spirv_cross_cpp REQUIRED)

View file

@ -431,7 +431,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
{ {
std::string vertex_src; std::string vertex_src;
if(info.shaders.vertex_path.empty()) { if(info.shaders.vertex_path.empty()) {
vertex_src = info.shaders.vertex_src; vertex_src = std::get<std::string>(info.shaders.vertex_src);
} else { } else {
const auto vertex_path = utility::format("{}.msl", info.shaders.vertex_path); const auto vertex_path = utility::format("{}.msl", info.shaders.vertex_path);
@ -453,7 +453,7 @@ GFXPipeline* GFXMetal::create_graphics_pipeline(const GFXGraphicsPipelineCreateI
{ {
std::string fragment_src; std::string fragment_src;
if(info.shaders.fragment_path.empty()) { if(info.shaders.fragment_path.empty()) {
fragment_src = info.shaders.fragment_src; fragment_src = std::get<std::string>(info.shaders.fragment_src);
} else { } else {
const auto fragment_path = utility::format("{}.msl", info.shaders.fragment_path); const auto fragment_path = utility::format("{}.msl", info.shaders.fragment_path);

View file

@ -1,17 +1,8 @@
#include "shadercompiler.hpp" #include "shadercompiler.hpp"
#include <iostream>
#if defined(PLATFORM_IOS) || defined(PLATFORM_TVOS) || defined(PLATFORM_WINDOWS)
#include <spirv_cpp.hpp> #include <spirv_cpp.hpp>
#include <spirv_msl.hpp> #include <spirv_msl.hpp>
#include <SPIRV/GlslangToSpv.h> #include <SPIRV/GlslangToSpv.h>
#else
#include <spirv_cross/spirv_cpp.hpp>
#include <spirv_cross/spirv_msl.hpp>
#include <glslang/Public/ShaderLang.h>
#include <SPIRV/GlslangToSpv.h>
#endif
#include "file.hpp" #include "file.hpp"
#include "log.hpp" #include "log.hpp"

View file

@ -294,13 +294,13 @@ CGRect toTopLeftSpace(NSRect frame) {
return NSRectToCGRect(frame); return NSRectToCGRect(frame);
} }
Rectangle platform::get_monitor_resolution() { prism::Rectangle platform::get_monitor_resolution() {
auto frame = toTopLeftSpace([[NSScreen mainScreen] frame]); auto frame = toTopLeftSpace([[NSScreen mainScreen] frame]);
return {static_cast<int32_t>(frame.origin.x), static_cast<int32_t>(frame.origin.y), static_cast<uint32_t>(frame.size.width), static_cast<uint32_t>(frame.size.height)}; return {static_cast<int32_t>(frame.origin.x), static_cast<int32_t>(frame.origin.y), static_cast<uint32_t>(frame.size.width), static_cast<uint32_t>(frame.size.height)};
} }
Rectangle platform::get_monitor_work_area() { prism::Rectangle platform::get_monitor_work_area() {
auto frame = toTopLeftSpace([[NSScreen mainScreen] visibleFrame]); auto frame = toTopLeftSpace([[NSScreen mainScreen] visibleFrame]);
return {static_cast<int32_t>(frame.origin.x), static_cast<int32_t>(frame.origin.y), static_cast<uint32_t>(frame.size.width), static_cast<uint32_t>(frame.size.height)}; return {static_cast<int32_t>(frame.origin.x), static_cast<int32_t>(frame.origin.y), static_cast<uint32_t>(frame.size.width), static_cast<uint32_t>(frame.size.height)};
@ -310,11 +310,11 @@ NSPoint get_fixed_cursor_point(NSPoint point) {
return {point.x, std::max(windows[0]->currentHeight - point.y, 0.0)}; return {point.x, std::max(windows[0]->currentHeight - point.y, 0.0)};
} }
Offset platform::get_cursor_position() { prism::Offset platform::get_cursor_position() {
return {static_cast<int32_t>(windows[0]->currentMousePos.x), static_cast<int32_t>(windows[0]->currentMousePos.y)}; return {static_cast<int32_t>(windows[0]->currentMousePos.x), static_cast<int32_t>(windows[0]->currentMousePos.y)};
} }
Offset platform::get_screen_cursor_position() { prism::Offset platform::get_screen_cursor_position() {
return {static_cast<int32_t>([NSEvent mouseLocation].x), static_cast<int32_t>([[NSScreen mainScreen] frame].size.height - [NSEvent mouseLocation].y)}; return {static_cast<int32_t>([NSEvent mouseLocation].x), static_cast<int32_t>([[NSScreen mainScreen] frame].size.height - [NSEvent mouseLocation].y)};
} }
@ -330,17 +330,17 @@ std::tuple<float, float> platform::get_right_stick_position() {
return {rightX, rightY}; return {rightX, rightY};
} }
Extent platform::get_window_size(const int index) { prism::Extent platform::get_window_size(const int index) {
auto window = get_window(index); auto window = get_window(index);
return {static_cast<uint32_t>(window->currentWidth), static_cast<uint32_t>(window->currentHeight)}; return {static_cast<uint32_t>(window->currentWidth), static_cast<uint32_t>(window->currentHeight)};
} }
Extent platform::get_window_drawable_size(const int index) { prism::Extent platform::get_window_drawable_size(const int index) {
auto window = get_window(index); auto window = get_window(index);
return {static_cast<uint32_t>(window->currentWidth * window->window.backingScaleFactor), static_cast<uint32_t>(window->currentHeight * window->window.backingScaleFactor)}; return {static_cast<uint32_t>(window->currentWidth * window->window.backingScaleFactor), static_cast<uint32_t>(window->currentHeight * window->window.backingScaleFactor)};
} }
Offset platform::get_window_position(const int index) { prism::Offset platform::get_window_position(const int index) {
auto window = get_window(index); auto window = get_window(index);
auto frame = toTopLeftSpace([window->window contentRectForFrameRect:[window->window frame]]); auto frame = toTopLeftSpace([window->window contentRectForFrameRect:[window->window frame]]);
@ -363,7 +363,7 @@ bool platform::get_mouse_button_down(const int button) {
return (button + 1) & [NSEvent pressedMouseButtons]; return (button + 1) & [NSEvent pressedMouseButtons];
} }
void platform::set_window_position(const int index, const Offset offset) { void platform::set_window_position(const int index, const prism::Offset offset) {
auto window = get_window(index); auto window = get_window(index);
NSPoint p; NSPoint p;
@ -373,7 +373,7 @@ void platform::set_window_position(const int index, const Offset offset) {
[window->window setFrameTopLeftPoint:p]; [window->window setFrameTopLeftPoint:p];
} }
void platform::set_window_size(const int index, const Extent extent) { void platform::set_window_size(const int index, const prism::Extent extent) {
auto window = get_window(index); auto window = get_window(index);
NSSize size; NSSize size;
@ -391,7 +391,7 @@ void platform::set_window_title(const int index, const std::string_view title) {
void platform::mute_output() {} void platform::mute_output() {}
void platform::unmute_output() {} void platform::unmute_output() {}
int platform::open_window(const std::string_view title, const Rectangle rect, const WindowFlags flags) { int platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) {
NativeWindow* native = new NativeWindow(); NativeWindow* native = new NativeWindow();
native->index = windows.size(); native->index = windows.size();
GameView* del = [[GameView alloc] init]; GameView* del = [[GameView alloc] init];

View file

@ -47,7 +47,7 @@ class DebugPass : public Pass {
public: public:
void initialize() override; void initialize() override;
void resize(const Extent extent) override; void resize(const prism::Extent extent) override;
void render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) override; void render_scene(Scene& scene, GFXCommandBuffer* commandBuffer) override;
@ -70,7 +70,7 @@ public:
private: private:
void createOffscreenResources(); void createOffscreenResources();
Extent extent; prism::Extent extent;
std::vector<SelectableObject> selectable_objects; std::vector<SelectableObject> selectable_objects;

View file

@ -18,6 +18,7 @@
#include "gfx.hpp" #include "gfx.hpp"
#include "gfx_commandbuffer.hpp" #include "gfx_commandbuffer.hpp"
#include "imgui_utility.hpp" #include "imgui_utility.hpp"
#include "screen.hpp"
const std::map<ImGuiKey, InputButton> imToPl = { const std::map<ImGuiKey, InputButton> imToPl = {
{ImGuiKey_Tab, InputButton::Tab}, {ImGuiKey_Tab, InputButton::Tab},

View file

@ -162,7 +162,7 @@ void DebugPass::initialize() {
} }
} }
void DebugPass::resize(const Extent extent) { void DebugPass::resize(const prism::Extent extent) {
this->extent = extent; this->extent = extent;
createOffscreenResources(); createOffscreenResources();

View file

@ -1,18 +1,10 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#ifdef PLATFORM_WINDOWS
#include <spirv_cpp.hpp> #include <spirv_cpp.hpp>
#include <spirv_msl.hpp> #include <spirv_msl.hpp>
#include <glslang/Public/ShaderLang.h> #include <glslang/Public/ShaderLang.h>
#include <SPIRV/GlslangToSpv.h> #include <SPIRV/GlslangToSpv.h>
#else
#include <spirv_cross/spirv_cpp.hpp>
#include <spirv_cross/spirv_msl.hpp>
#include <glslang/Public/ShaderLang.h>
#include <SPIRV/GlslangToSpv.h>
#endif
#include "DirStackIncluder.h" #include "DirStackIncluder.h"
#include "log.hpp" #include "log.hpp"