summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Halase <jordan@halase.me>2019-11-04 10:58:19 -0600
committerJordan Halase <jordan@halase.me>2019-11-04 10:58:19 -0600
commite552c98e63eea3a18a0be076e5e3ea3796813cad (patch)
tree0c7d813f95b39e0828df8aba32cac84ff17f7137
parent977157a1eea893545e7a1c7b8c0a3e6e20dced41 (diff)
Add more arguments
-rwxr-xr-xmain.c75
1 files changed, 50 insertions, 25 deletions
diff --git a/main.c b/main.c
index 0976ef1..d8b9b1f 100755
--- a/main.c
+++ b/main.c
@@ -62,9 +62,11 @@ PERFORMANCE OF THIS SOFTWARE.
struct Arguments {
bool validation;
+ bool verbose;
+ bool continuous;
};
-static void printUsage(const char *cmd, struct Arguments *args, bool error)
+static void printUsage(const char *cmd, const struct Arguments *args, const bool error)
{
FILE *fp = error ? stderr : stdout;
const char *const defaultStr = "\t[default]\n";
@@ -75,24 +77,45 @@ static void printUsage(const char *cmd, struct Arguments *args, bool error)
args->validation ? defaultStr : newline);
fprintf(fp, " --no-validation\tRun without Vulkan validation layers or debug callback%s",
!args->validation ? defaultStr : newline);
+ fprintf(fp, " -c, --continuous\tDraw continuously as fast as possible%s",
+ args->continuous ? defaultStr : newline);
+ fprintf(fp, " -v, --verbose\t\tPrint verbose window system events%s",
+ args->verbose ? defaultStr : newline);
exit(error);
}
-static void parseArgs(int argc, char **argv, struct Arguments *args)
+static void parseArgs(const int argc, char *const *const argv, struct Arguments *const args)
{
if (argc < 2) {
return;
}
- if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
- printUsage(argv[0], args, false);
- } else if (!strcmp(argv[1], "--validation")) {
- args->validation = true;
- } else if (!strcmp(argv[1], "--no-validation")) {
- args->validation = false;
- } else {
- fprintf(stderr, "Unknown option `%s`\n", argv[1]);
- printUsage(argv[0], args, true);
+ const struct Arguments immutable = *args;
+ int i;
+ for (i = 1; i < argc; ++i) {
+ if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
+ printUsage(argv[0], &immutable, false);
+ } else if (!strcmp(argv[i], "--validation")) {
+ args->validation = true;
+ } else if (!strcmp(argv[i], "--no-validation")) {
+ args->validation = false;
+ } else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--continuous")) {
+ args->continuous = true;
+ } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--verbose")) {
+ args->verbose = true;
+ } else {
+ fprintf(stderr, "Unknown option `%s`\n", argv[1]);
+ printUsage(argv[0], &immutable, true);
+ }
+ }
+}
+
+static void printArgs(int argc, char **argv)
+{
+ int i;
+ for (i = 0; i < argc-1; ++i) {
+ printf("%s ", argv[i]);
}
+ printf("%s\n", argv[i]);
}
/** Vulkan allocation callbacks if we ever decide to use them when debugging.
@@ -1629,15 +1652,15 @@ static void rvkFatal(struct RenderVulkan *vk)
int running = 1;
+struct Arguments args;
+
uint32_t framesDrawn;
PuglStatus onDisplay(PuglView *view)
{
struct RenderVulkan *vk = puglGetHandle(view);
-
uint32_t imageIndex;
VkResult result;
-
if ((result = vk->dev->vkAcquireNextImageKHR(
vk->device,
vk->swapchain.rawSwapchain,
@@ -1691,13 +1714,13 @@ PuglStatus onDisplay(PuglView *view)
vk->dev->vkQueuePresentKHR(vk->graphicsQueue, &presentInfo);
- //++framesDrawn;
+ if (args.continuous) ++framesDrawn;
return PUGL_SUCCESS;
}
PuglStatus onEvent(PuglView *view, const PuglEvent *e)
{
- printEvent(e, "Event:\t", true);
+ printEvent(e, "Event:\t", args.verbose);
switch (e->type) {
case PUGL_EXPOSE:
onDisplay(view);
@@ -1718,14 +1741,11 @@ int main(int argc, char **argv)
XInitThreads();
#endif
- struct Arguments args = { 0 };
args.validation = true;
+ args.verbose = false;
+ args.continuous = false;
parseArgs(argc, argv, &args);
- if (args.validation) {
- printf("Using Vulkan validation layers and debug callback\n");
- } else {
- printf("Not using Vulkan validation layers or debug callback\n");
- }
+ printArgs(argc, argv);
/* Vulkan application that uses Pugl for windows and events */
struct RenderVulkan *vk;
@@ -1743,13 +1763,18 @@ int main(int argc, char **argv)
printf("Opened Vulkan Device Successfully\n");
puglSetEventFunc(vk->view, onEvent);
- //PuglFpsPrinter fpsPrinter = { puglGetTime(world) };
+ PuglFpsPrinter fpsPrinter = { puglGetTime(vk->world) };
puglShowWindow(vk->view);
while (running) {
- puglPollEvents(vk->world, -1);
- //puglPostRedisplay(view);
+ if (args.continuous) {
+ puglPostRedisplay(vk->view);
+ } else {
+ puglPollEvents(vk->world, -1);
+ }
puglDispatchEvents(vk->world);
- //puglPrintFps(world, &fpsPrinter, &framesDrawn);
+ if (args.continuous) {
+ puglPrintFps(vk->world, &fpsPrinter, &framesDrawn);
+ }
}
rvkDestroyApplication(vk);