Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new vulkan SDL c template #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions templates/vulkan-sdl/flextVk.c.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
@require(passthru, functions, enums, options, version, extensions)
/* WARNING: This file was automatically generated */
/* Do not edit. */

#include "flextVk.h"
#include <SDL.h>

#ifdef __cplusplus
extern "C" {
#endif

@for category,funcs in functions:
@if funcs:
@for f in funcs:
PFNVK@f.name.upper()_PROC* flextvk@f.name = NULL;
@end
@end
@end

static void *vulkanLibrary = NULL;

void flextVkShutdown(void) {
SDL_UnloadObject(vulkanLibrary);
vulkanLibrary = NULL;
}

int flextVkInit(void) {
#if defined(__linux__)
vulkanLibrary = SDL_LoadObject("libvulkan.so");
if (vulkanLibrary == NULL) {
vulkanLibrary = SDL_LoadObject("libvulkan.so.1");
}
#elif defined(__APPLE__)
vulkanLibrary = SDL_LoadObject("libvulkan.dylib");
#elif defined(_WIN32)
vulkanLibrary = SDL_LoadObject("vulkan-1.dll");
#else
#error unsupported platform
#endif
if (vulkanLibrary == NULL) {
return SDL_SetError("Could not load the vulkan library");
}
@for category,funcs in functions:
@if funcs:
@for f in funcs:
@if f.name in ['GetInstanceProcAddr', 'EnumerateInstanceExtensionProperties', 'EnumerateInstanceLayerProperties', 'CreateInstance']:
flextvk@f.name = (PFNVK@f.name.upper()_PROC*)SDL_LoadFunction(vulkanLibrary, "vk@f.name");
@end
@if f.name in ['EnumerateInstanceVersion']:
if (flextvkGetInstanceProcAddr) {
flextvk@f.name = (PFNVK@f.name.upper()_PROC*)flextvkGetInstanceProcAddr(NULL, "vk@f.name");
} else {
return SDL_SetError("Could not load vkGetInstanceProcAddr from vulkan library");
}
@end
@end
@end
@end
return 0;
}

void flextVkInitInstance(VkInstance instance) {
@for category,funcs in functions:
@if funcs:
@for f in funcs:
@if f.name not in ['GetInstanceProcAddr', 'EnumerateInstanceVersion', 'EnumerateInstanceExtensionProperties', 'EnumerateInstanceLayerProperties', 'CreateInstance']:
flextvk@f.name = (PFNVK@f.name.upper()_PROC*)flextvkGetInstanceProcAddr(instance, "vk@f.name");
@end
@end
@end
@end
}

#ifdef __cplusplus
}
#endif
125 changes: 125 additions & 0 deletions templates/vulkan-sdl/flextVk.h.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
@require(passthru, functions, enums, options, version, extensions, args)
#ifndef _flextvk_h_
#define _flextvk_h_
/*
This file was generated using https://github.com/mosra/flextgl:

path/to/flextGLgen.py @args

Do not edit directly, modify the template or profile and regenerate.
*/

#include <stdint.h>
#include <stddef.h>

/* Defensive include guards */

#if defined(VULKAN_H_)
#error Attempt to include auto-generated header after including vulkan.h
#endif
#if defined(VK_PLATFORM_H_)
#error Attempt to include auto-generated header after including vk_platform.h
#endif

#define VULKAN_H_
#define VK_PLATFORM_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Verbatim copied from upstream vk_platform.h */
#if defined(_WIN32)
// On Windows, Vulkan commands use the stdcall convention
#define VKAPI_ATTR
#define VKAPI_CALL __stdcall
#define VKAPI_PTR VKAPI_CALL
#elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7
#error "Vulkan isn't supported for the 'armeabi' NDK ABI"
#elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE)
// On Android 32-bit ARM targets, Vulkan functions use the "hardfloat"
// calling convention, i.e. float parameters are passed in registers. This
// is true even if the rest of the application passes floats on the stack,
// as it does by default when compiling for the armeabi-v7a NDK ABI.
#define VKAPI_ATTR __attribute__((pcs("aapcs-vfp")))
#define VKAPI_CALL
#define VKAPI_PTR VKAPI_ATTR
#else
// On other platforms, use the default calling convention
#define VKAPI_ATTR
#define VKAPI_CALL
#define VKAPI_PTR
#endif

/* Enums */

@enums

/* Data types */

@passthru

/* The following function pointers are loaded globally by calling flextVkInit() */
@for cat,funcs in functions:

@for f in funcs:
@if f.name in ['GetInstanceProcAddr', 'EnumerateInstanceExtensionProperties', 'EnumerateInstanceLayerProperties', 'CreateInstance']:
typedef @f.returntype (VKAPI_PTR PFNVK@f.name.upper()_PROC (@f.param_list_string()));
@end
@end

@for f in funcs:
@if f.name in ['GetInstanceProcAddr', 'EnumerateInstanceExtensionProperties', 'EnumerateInstanceLayerProperties', 'CreateInstance']:
VKAPI_PTR PFNVK@f.name.upper()_PROC* flextvk@f.name;
@end
@end

@for f in funcs:
@if f.name in ['GetInstanceProcAddr', 'EnumerateInstanceExtensionProperties', 'EnumerateInstanceLayerProperties', 'CreateInstance']:
#define vk@f.name flextvk@f.name
@end
@end

@end

/* Function pointers */

@for cat,funcs in functions:
@if funcs:

/* VK_@cat */

@for f in funcs:
@if f.name not in ['GetInstanceProcAddr', 'EnumerateInstanceExtensionProperties', 'EnumerateInstanceLayerProperties', 'CreateInstance']:
typedef @f.returntype (VKAPI_PTR PFNVK@f.name.upper()_PROC (@f.param_list_string()));
@end
@end

@for f in funcs:
@if f.name not in ['GetInstanceProcAddr', 'EnumerateInstanceExtensionProperties', 'EnumerateInstanceLayerProperties', 'CreateInstance']:
VKAPI_PTR PFNVK@f.name.upper()_PROC* flextvk@f.name;
@end
@end

@for f in funcs:
@if f.name not in ['GetInstanceProcAddr', 'EnumerateInstanceExtensionProperties', 'EnumerateInstanceLayerProperties', 'CreateInstance']:
#define vk@f.name flextvk@f.name
@end
@end

@end
@end

/* Global function pointer initialization. Returns 0 on success or anything else on error. Use SDL_GetError() to get more details */
int flextVkInit(void);
/* Unload the global library handle */
void flextVkShutdown(void);

/* Instance-specific function pointer initialization */
void flextVkInitInstance(VkInstance instance);

#ifdef __cplusplus
}
#endif

#endif