get Gryphn to compile on Linux
This commit is contained in:
+17
-8
@@ -1,12 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(ChemistryRenderingApp LANGUAGES C CXX OBJCXX) # OBJCXX is required for Metal .mm files
|
||||
add_executable(ChemistryRenderingApp main.mm)
|
||||
target_link_libraries(ChemistryRenderingApp PRIVATE
|
||||
"-framework Metal"
|
||||
"-framework Foundation"
|
||||
"-framework QuartzCore"
|
||||
"-framework Cocoa"
|
||||
)
|
||||
project(ChemistryRenderingApp LANGUAGES C CXX)
|
||||
if (APPLE)
|
||||
add_executable(ChemistryRenderingApp main.mm)
|
||||
target_link_libraries(ChemistryRenderingApp PRIVATE
|
||||
"-framework Metal"
|
||||
"-framework Foundation"
|
||||
"-framework QuartzCore"
|
||||
"-framework Cocoa"
|
||||
)
|
||||
endif()
|
||||
if (UNIX AND NOT APPLE)
|
||||
add_executable(ChemistryRenderingApp main.cpp)
|
||||
endif()
|
||||
target_include_directories(ChemistryRenderingApp PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
target_include_directories(ChemistryRenderingApp PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/glfw/include/")
|
||||
target_link_libraries(ChemistryRenderingApp PRIVATE GryphnLoader glfw)
|
||||
@@ -17,5 +22,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_subdirectory(Gryphn)
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
|
||||
set(GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE)
|
||||
set(GLFW_BUILD_X11 ON CACHE BOOL "" FORCE)
|
||||
|
||||
add_subdirectory(glfw)
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(Gryphn LANGUAGES C CXX OBJCXX) # OBJCXX is required for Metal .mm files
|
||||
project(Gryphn LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
@@ -10,4 +10,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
# Add subdirectories
|
||||
add_subdirectory(GryphnLoader)
|
||||
add_subdirectory(apis/GryphnMetal)
|
||||
if (APPLE)
|
||||
add_subdirectory(apis/GryphnMetal)
|
||||
endif()
|
||||
|
||||
@@ -17,7 +17,7 @@ gnReturnCode gnGetAvaliableBackends(gnVersion version, uint32_t* avaliable_backe
|
||||
}
|
||||
*avaliable_backends += 1;
|
||||
}
|
||||
gnCloseLib(&metalLib);
|
||||
}
|
||||
gnCloseLib(&metalLib);
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ int gnLibValid(const gnLib* lib) {
|
||||
#ifdef GN_PLATFORM_MACOS
|
||||
return lib->dylib != 0;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* gnLoadLibFunction(const gnLib* lib, const char* function) {
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
#include "Gryphn/gryphn.h"
|
||||
#include <iostream>
|
||||
#include "stdlib.h"
|
||||
#define GLFW_EXPOSE_NATIVE_X11
|
||||
#include "glfw/include/GLFW/glfw3.h"
|
||||
#include "glfw/include/GLFW/glfw3native.h"
|
||||
|
||||
#define CONCAT_IMPL(a, b) a##b
|
||||
#define CONCAT(a, b) CONCAT_IMPL(a, b)
|
||||
#define CHECK(func) \
|
||||
gnReturnCode CONCAT(res, __LINE__) = (func); \
|
||||
if (CONCAT(res, __LINE__) != GN_SUCCESS) { \
|
||||
std::cout << "Gryphn Error at line " << __LINE__ \
|
||||
<< ": " << CONCAT(res, __LINE__) << "\n"; \
|
||||
}
|
||||
|
||||
GLFWwindow* window;
|
||||
CAMetalLayer* layer;
|
||||
gnVersion version = gnCreateVersion(1, 0, 0);
|
||||
gnInstance instance;
|
||||
gnPhysicalDevice pysicalDevice;
|
||||
gnDevice device;
|
||||
gnSurface surface;
|
||||
|
||||
void createInstance() {
|
||||
uint32_t backendCount = 0;
|
||||
CHECK(gnGetAvaliableBackends(version, &backendCount, nullptr));
|
||||
if (backendCount == 0) {
|
||||
throw std::runtime_error("Gryphn returned 0 avaliable backends");
|
||||
}
|
||||
gnBackend* backends = (gnBackend*)malloc(sizeof(gnBackend) * backendCount);
|
||||
CHECK(gnGetAvaliableBackends(version, &backendCount, backends));
|
||||
const char* extensions[2] = {
|
||||
"GN_EXT_surface",
|
||||
"GN_EXT_surface_cocoa"
|
||||
};
|
||||
|
||||
gnInstanceCreateInfo createInfo = {
|
||||
.backend = backends[0],
|
||||
.info = {
|
||||
.applicationName = "Chemistry Rendering App",
|
||||
.applicationVersion = gnCreateVersion(0, 0, 1),
|
||||
.engineName = "Chemistry Rendering Engine",
|
||||
.enginnVersion = gnCreateVersion(0, 0, 1)
|
||||
},
|
||||
.enabledValidationLayerCount = 0,
|
||||
.enabledValidationLayers = nullptr,
|
||||
.enabledExtensionCount = 2,
|
||||
.enabledExtensions = extensions
|
||||
};
|
||||
CHECK(gnCreateInstance(&instance, &createInfo));
|
||||
free(backends);
|
||||
}
|
||||
|
||||
void createDevice() {
|
||||
uint32_t physicalDeviceCount;
|
||||
CHECK(gnEnumeratePhysicalDevices(instance, &physicalDeviceCount, nullptr));
|
||||
gnPhysicalDevice* devices = (gnPhysicalDevice*)malloc(sizeof(gnPhysicalDevice) * physicalDeviceCount);
|
||||
CHECK(gnEnumeratePhysicalDevices(instance, &physicalDeviceCount, devices));
|
||||
|
||||
std::cout << "Found " << physicalDeviceCount << " physical devices:\n";
|
||||
for (int i = 0; i < physicalDeviceCount; i++) {
|
||||
gnPhysicalDeviceProperties properties;
|
||||
gnGetPhysicalDeviceProperties(devices[i], &properties);
|
||||
std::cout << "Name: " << properties.deviceName << "\n";
|
||||
}
|
||||
|
||||
pysicalDevice = devices[0];
|
||||
|
||||
const char* extensions[1] = {
|
||||
"GN_EXT_swapchain"
|
||||
};
|
||||
|
||||
gnDeviceCreateInfo createInfo = {
|
||||
.physicalDevice = pysicalDevice,
|
||||
.enabledExtensionCount = 1,
|
||||
.enabledExtensions = extensions
|
||||
};
|
||||
CHECK(gnCreateDevice(instance, &createInfo, &device));
|
||||
}
|
||||
|
||||
void createSurface() {
|
||||
// NSWindow* nswin = glfwGetCocoaWindow((GLFWwindow*)window);
|
||||
// NSView* view = [nswin contentView];
|
||||
// layer = [CAMetalLayer layer];
|
||||
// [view setWantsLayer:YES];
|
||||
// [view setLayer:layer];
|
||||
// layer.contentsScale = [nswin backingScaleFactor];
|
||||
|
||||
// gnMetalSurfaceCreateInfo createInfo = {
|
||||
// .metalLayer = layer
|
||||
// };
|
||||
// CHECK(gnCreateMetalSurface(instance, &createInfo, &surface));
|
||||
|
||||
// gnSurfaceCapabilities capabilites;
|
||||
// gnGetSurfaceCapabilities(pysicalDevice, surface, &capabilites);
|
||||
}
|
||||
|
||||
void createSwapchain() {
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (!glfwInit()) {
|
||||
std::cout << "Failed to init GLFW\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
window = glfwCreateWindow(640, 360, "Chemistry Rendering App", nullptr, nullptr);
|
||||
if (!window) {
|
||||
std::cerr << "Failed to create window\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
try {
|
||||
createInstance();
|
||||
createDevice();
|
||||
createSurface();
|
||||
createSwapchain();
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Caught Exception: " << e.what() << "\n";
|
||||
return 0;
|
||||
}
|
||||
glfwDestroyWindow(window);
|
||||
gnDestroySurface(instance, &surface);
|
||||
gnDestroyDevice(&device);
|
||||
gnDestroyInstance(&instance);
|
||||
}
|
||||
Reference in New Issue
Block a user