diff options
Diffstat (limited to 'cube')
| -rw-r--r-- | cube/cube.c | 34 | ||||
| -rw-r--r-- | cube/cube.cpp | 20 |
2 files changed, 37 insertions, 17 deletions
diff --git a/cube/cube.c b/cube/cube.c index 5382cd0e..9cbc45e5 100644 --- a/cube/cube.c +++ b/cube/cube.c @@ -99,10 +99,10 @@ void DbgMsg(char *fmt, ...) { #elif defined __ANDROID__ #include <android/log.h> -#define ERR_EXIT(err_msg, err_class) \ - do { \ +#define ERR_EXIT(err_msg, err_class) \ + do { \ ((void)__android_log_print(ANDROID_LOG_INFO, "Vulkan Cube", err_msg)); \ - exit(1); \ + exit(1); \ } while (0) #ifdef VARARGS_WORKS_ON_ANDROID void DbgMsg(const char *fmt, ...) { @@ -112,8 +112,8 @@ void DbgMsg(const char *fmt, ...) { va_end(va); } #else // VARARGS_WORKS_ON_ANDROID -#define DbgMsg(fmt, ...) \ - do { \ +#define DbgMsg(fmt, ...) \ + do { \ ((void)__android_log_print(ANDROID_LOG_INFO, "Vulkan Cube", fmt, ##__VA_ARGS__)); \ } while (0) #endif // VARARGS_WORKS_ON_ANDROID @@ -529,22 +529,21 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debug_messenger_callback(VkDebugUtilsMessageSever #ifdef _WIN32 in_callback = true; - if (!demo->suppress_popups) - MessageBox(NULL, message, "Alert", MB_OK); + if (!demo->suppress_popups) MessageBox(NULL, message, "Alert", MB_OK); in_callback = false; #elif defined(ANDROID) if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT) { - __android_log_print(ANDROID_LOG_INFO, APP_SHORT_NAME, "%s", message); + __android_log_print(ANDROID_LOG_INFO, APP_SHORT_NAME, "%s", message); } else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT) { - __android_log_print(ANDROID_LOG_WARN, APP_SHORT_NAME, "%s", message); + __android_log_print(ANDROID_LOG_WARN, APP_SHORT_NAME, "%s", message); } else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT) { __android_log_print(ANDROID_LOG_ERROR, APP_SHORT_NAME, "%s", message); } else if (messageSeverity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) { __android_log_print(ANDROID_LOG_VERBOSE, APP_SHORT_NAME, "%s", message); } else { - __android_log_print(ANDROID_LOG_INFO, APP_SHORT_NAME, "%s", message); + __android_log_print(ANDROID_LOG_INFO, APP_SHORT_NAME, "%s", message); } #else @@ -772,8 +771,16 @@ static void demo_draw_build_cmd(struct demo *demo, VkCommandBuffer cmd_buf) { &demo->swapchain_image_resources[demo->current_buffer].descriptor_set, 0, NULL); VkViewport viewport; memset(&viewport, 0, sizeof(viewport)); - viewport.height = (float)demo->height; - viewport.width = (float)demo->width; + float viewport_dimension; + if (demo->width < demo->height) { + viewport_dimension = (float)demo->width; + viewport.y = (demo->height - demo->width) / 2.0f; + } else { + viewport_dimension = (float)demo->height; + viewport.x = (demo->width - demo->height) / 2.0f; + } + viewport.height = viewport_dimension; + viewport.width = viewport_dimension; viewport.minDepth = (float)0.0f; viewport.maxDepth = (float)1.0f; vkCmdSetViewport(cmd_buf, 0, 1, &viewport); @@ -3763,7 +3770,7 @@ static void demo_init(struct demo *demo, int argc, char **argv) { memset(demo, 0, sizeof(*demo)); demo->presentMode = VK_PRESENT_MODE_FIFO_KHR; demo->frameCount = INT32_MAX; - + for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--use_staging") == 0) { demo->use_staging_buffer = true; @@ -3953,7 +3960,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, #elif defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK) static void demo_main(struct demo *demo, void *view, int argc, const char *argv[]) { - demo_init(demo, argc, (char **)argv); demo->window = view; demo_init_vk_swapchain(demo); diff --git a/cube/cube.cpp b/cube/cube.cpp index abe80a88..4af97856 100644 --- a/cube/cube.cpp +++ b/cube/cube.cpp @@ -850,9 +850,23 @@ void Demo::draw_build_cmd(vk::CommandBuffer commandBuffer) { commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline); commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipeline_layout, 0, 1, &swapchain_image_resources[current_buffer].descriptor_set, 0, nullptr); - - auto const viewport = - vk::Viewport().setWidth((float)width).setHeight((float)height).setMinDepth((float)0.0f).setMaxDepth((float)1.0f); + float viewport_dimension; + float viewport_x = 0.0f; + float viewport_y = 0.0f; + if (width < height) { + viewport_dimension = (float)width; + viewport_y = (height - width) / 2.0f; + } else { + viewport_dimension = (float)height; + viewport_x = (width - height) / 2.0f; + } + auto const viewport = vk::Viewport() + .setX(viewport_x) + .setY(viewport_y) + .setWidth((float)viewport_dimension) + .setHeight((float)viewport_dimension) + .setMinDepth((float)0.0f) + .setMaxDepth((float)1.0f); commandBuffer.setViewport(0, 1, &viewport); vk::Rect2D const scissor(vk::Offset2D(0, 0), vk::Extent2D(width, height)); |
