add support for creating a metal surface
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
#include "Gryphn/gryphn.h"
|
||||
#include <iostream>
|
||||
#include "stdlib.h"
|
||||
#include "glfw/include/GLFW/glfw3.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;
|
||||
gnVersion version = gnCreateVersion(1, 0, 0);
|
||||
gnInstance instance;
|
||||
gnDevice device;
|
||||
|
||||
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));
|
||||
|
||||
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 = 0,
|
||||
.enabledExtensions = nullptr
|
||||
};
|
||||
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";
|
||||
}
|
||||
|
||||
gnDeviceCreateInfo createInfo = {
|
||||
.physicalDevice = devices[0]
|
||||
};
|
||||
CHECK(gnCreateDevice(instance, &createInfo, &device));
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (!glfwInit()) {
|
||||
std::cout << "Failed to init GLFW\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(640, 360, "Chemistry Rendering App", nullptr, nullptr);
|
||||
if (!window) {
|
||||
std::cerr << "Failed to create window\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
try {
|
||||
createInstance();
|
||||
createDevice();
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Caught Exception: " << e.what() << "\n";
|
||||
return 0;
|
||||
}
|
||||
glfwDestroyWindow(window);
|
||||
gnDestroyDevice(&device);
|
||||
gnDestroyInstance(&instance);
|
||||
}
|
||||
Reference in New Issue
Block a user