diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/hello-world/vulkan-api.cpp | 22 | ||||
| -rw-r--r-- | examples/platform-test/main.cpp | 102 |
2 files changed, 122 insertions, 2 deletions
diff --git a/examples/hello-world/vulkan-api.cpp b/examples/hello-world/vulkan-api.cpp index cc52956ce..3581563d4 100644 --- a/examples/hello-world/vulkan-api.cpp +++ b/examples/hello-world/vulkan-api.cpp @@ -41,6 +41,10 @@ int initializeVulkanDevice(VulkanAPI& api) HMODULE module = ::LoadLibraryA(dynamicLibraryName); api.vulkanLibraryHandle = (void*)module; #define VK_API_GET_GLOBAL_PROC(x) api.x = (PFN_##x)GetProcAddress(module, #x); +#elif SLANG_APPLE_FAMILY + dynamicLibraryName = "libvulkan.dylib"; + api.vulkanLibraryHandle = dlopen(dynamicLibraryName, RTLD_NOW); +#define VK_API_GET_GLOBAL_PROC(x) api.x = (PFN_##x)dlsym(api.vulkanLibraryHandle, #x); #else dynamicLibraryName = "libvulkan.so.1"; api.vulkanLibraryHandle = dlopen(dynamicLibraryName, RTLD_NOW); @@ -78,10 +82,16 @@ int initializeVulkanDevice(VulkanAPI& api) applicationInfo.engineVersion = 1; applicationInfo.applicationVersion = 1; const char* instanceExtensions[] = { +#if SLANG_APPLE_FAMILY + VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, +#endif VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_EXTENSION_NAME, }; VkInstanceCreateInfo instanceCreateInfo = {VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO}; +#if SLANG_APPLE_FAMILY + instanceCreateInfo.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; +#endif instanceCreateInfo.pApplicationInfo = &applicationInfo; instanceCreateInfo.enabledExtensionCount = SLANG_COUNT_OF(instanceExtensions); instanceCreateInfo.ppEnabledExtensionNames = &instanceExtensions[0]; @@ -150,14 +160,22 @@ int initializeVulkanDevice(VulkanAPI& api) if (api.queueFamilyIndex == -1) return -1; +#if SLANG_APPLE_FAMILY + const char* deviceExtensions[] = { + "VK_KHR_portability_subset", + }; +#endif + VkDeviceQueueCreateInfo queueCreateInfo = {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}; float queuePriority = 0.0f; queueCreateInfo.queueFamilyIndex = api.queueFamilyIndex; queueCreateInfo.queueCount = 1; queueCreateInfo.pQueuePriorities = &queuePriority; deviceCreateInfo.pQueueCreateInfos = &queueCreateInfo; - deviceCreateInfo.enabledExtensionCount = 0; - deviceCreateInfo.ppEnabledExtensionNames = nullptr; +#if SLANG_APPLE_FAMILY + deviceCreateInfo.enabledExtensionCount = SLANG_COUNT_OF(deviceExtensions); + deviceCreateInfo.ppEnabledExtensionNames = &deviceExtensions[0]; +#endif RETURN_ON_FAIL(api.vkCreateDevice(api.physicalDevice, &deviceCreateInfo, nullptr, &api.device)); // Load device functions. diff --git a/examples/platform-test/main.cpp b/examples/platform-test/main.cpp new file mode 100644 index 000000000..24673db1c --- /dev/null +++ b/examples/platform-test/main.cpp @@ -0,0 +1,102 @@ +#include <slang.h> +#include "tools/platform/window.h" +#include "examples/example-base/example-base.h" + +using namespace gfx; +using namespace Slang; + +struct PlatformTest : public WindowedAppBase +{ + +void onSizeChanged() +{ + printf("onSizeChanged\n"); +} + +void onFocus() +{ + printf("onFocus\n"); +} + +void onLostFocus() +{ + printf("onLostFocus\n"); +} + +void onKeyDown(platform::KeyEventArgs args) +{ + printf("onKeyDown(key=0x%02x, buttons=0x%02x)\n", args.key, args.buttons); +} + +void onKeyUp(platform::KeyEventArgs args) +{ + printf("okKeyUp(key=0x%02x, buttons=0x%02x)\n", args.key, args.buttons); +} + +void onKeyPress(platform::KeyEventArgs args) +{ + printf("onKeyPress(keyChar=0x%02x)\n", args.keyChar); +} + +void onMouseMove(platform::MouseEventArgs args) +{ + printf("onMouseMove(x=%d, y=%d, delta=%d, buttons=0x%02x\n", args.x, args.y, args.delta, args.buttons); +} + +void onMouseDown(platform::MouseEventArgs args) +{ + printf("onMouseDown(x=%d, y=%d, delta=%d, buttons=0x%02x\n", args.x, args.y, args.delta, args.buttons); +} + +void onMouseUp(platform::MouseEventArgs args) +{ + printf("onMouseUp(x=%d, y=%d, delta=%d, buttons=0x%02x\n", args.x, args.y, args.delta, args.buttons); +} + +void onMouseWheel(platform::MouseEventArgs args) +{ + printf("onMouseWheel(x=%d, y=%d, delta=%d, buttons=0x%02x\n", args.x, args.y, args.delta, args.buttons); +} + +Slang::Result initialize() +{ + initializeBase("platform-test", 1024, 768); + + gWindow->events.sizeChanged = [this]() { onSizeChanged(); }; + gWindow->events.focus = [this]() { onFocus(); }; + gWindow->events.lostFocus = [this]() { onLostFocus(); }; + gWindow->events.keyDown = [this](const platform::KeyEventArgs& e) { onKeyDown(e); }; + gWindow->events.keyUp = [this](const platform::KeyEventArgs& e) { onKeyUp(e); }; + gWindow->events.keyPress = [this](const platform::KeyEventArgs& e) { onKeyPress(e); }; + gWindow->events.mouseMove = [this](const platform::MouseEventArgs& e) { onMouseMove(e); }; + gWindow->events.mouseDown = [this](const platform::MouseEventArgs& e) { onMouseDown(e); }; + gWindow->events.mouseUp = [this](const platform::MouseEventArgs& e) { onMouseUp(e); }; + gWindow->events.mouseWheel = [this](const platform::MouseEventArgs& e) { onMouseWheel(e); }; + + return SLANG_OK; +} + +virtual void renderFrame(int frameBufferIndex) override +{ + ComPtr<ICommandBuffer> commandBuffer = gTransientHeaps[frameBufferIndex]->createCommandBuffer(); + + auto renderEncoder = commandBuffer->encodeRenderCommands(gRenderPass, gFramebuffers[frameBufferIndex]); + + gfx::Viewport viewport = {}; + viewport.maxZ = 1.0f; + viewport.extentX = (float)windowWidth; + viewport.extentY = (float)windowHeight; + renderEncoder->setViewportAndScissor(viewport); + + renderEncoder->endEncoding(); + commandBuffer->close(); + gQueue->executeCommandBuffer(commandBuffer); + + gSwapchain->present(); +} + +}; + +// This macro instantiates an appropriate main function to +// run the application defined above. +PLATFORM_UI_MAIN(innerMain<PlatformTest>) |
