{% import "utils.j2" as u with context -%}
{{ preamble }}

#ifndef GLOAM_{{ guard }}
#define GLOAM_{{ guard }}
{# ---- System-header conflict guards ---------------------------------------
   These prevent including both the platform/system GL or Vulkan headers and
   this gloam header, which would cause duplicate declarations. Using
   reserved identifiers (double-underscore prefixed) requires suppressing the
   clang warning for that specific pragma block. #}
{%- if fs.spec_name in ["gl", "gles1", "gles2", "glcore"] %}
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
{%- for api in fs.apis %}
{%- if api in ["gl", "glcore"] %}
{{ u.header_error("__gl_h_",     "OpenGL (gl.h)",     api) }}
{{ u.header_error("__glext_h_",  "OpenGL (glext.h)",  api) }}
{%- elif api == "gles1" %}
{{ u.header_error("__gl_h_",       "OpenGL ES 1 (gl.h)",   api) }}
{{ u.header_error("__gles1_gl_h_", "OpenGL ES 1",          api) }}
{%- elif api == "gles2" %}
{{ u.header_error("__gl2_h_",       "OpenGL ES 2 (gl2.h)", api) }}
{{ u.header_error("__gles2_gl2_h_", "OpenGL ES 2",         api) }}
{{ u.header_error("__gl3_h_",       "OpenGL ES 3 (gl3.h)", api) }}
{{ u.header_error("__gles2_gl3_h_", "OpenGL ES 3",         api) }}
{%- endif %}
{%- endfor %}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
{%- elif fs.spec_name == "vk" and not external_headers %}
{{ u.header_error("VULKAN_H_",      "Vulkan (vulkan.h)",      "vulkan") }}
{{ u.header_error("VULKAN_CORE_H_", "Vulkan (vulkan_core.h)", "vulkan") }}
{%- elif fs.spec_name == "egl" %}
{{ u.header_error("__egl_h_", "EGL (egl.h)", "egl") }}
{%- elif fs.spec_name == "glx" %}
{{ u.header_error("GLX_H", "GLX (glx.h)", "glx") }}
{%- elif fs.spec_name == "wgl" %}
{{ u.header_error("__wgl_h_", "WGL (wgl.h)", "wgl") }}
{%- endif %}

/* ---- Platform detection ------------------------------------------------ */
#ifndef GLOAM_PLATFORM_DETECTED_
#define GLOAM_PLATFORM_DETECTED_
#if defined(__CYGWIN__) || defined(_WIN32)
#  define GLOAM_PLATFORM_WINDOWS 1
#endif
#if defined(__linux)
#  define GLOAM_PLATFORM_LINUX 1
#endif
#endif /* GLOAM_PLATFORM_DETECTED_ */

#ifndef GLOAM_HAS_ENUM_BASE_TYPE
#if defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
#  define GLOAM_HAS_ENUM_BASE_TYPE 1
#else
#  define GLOAM_HAS_ENUM_BASE_TYPE 0
#endif
#endif
{%- if fs.is_vulkan %}

#ifndef GLOAM_FORCE_INLINE
#if defined(_MSC_VER)
#  define GLOAM_FORCE_INLINE static __forceinline
#elif defined(__GNUC__) || defined(__clang__)
#  define GLOAM_FORCE_INLINE static inline __attribute__((always_inline))
#else
#  define GLOAM_FORCE_INLINE static inline
#endif
#endif
{%- endif %}
{%- if fs.spec_name == "glx" %}

#ifdef GLOAM_PLATFORM_LINUX

#include <gloam/gl.h>

#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

{%- elif fs.spec_name == "wgl" %}

#ifdef GLOAM_PLATFORM_WINDOWS

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>

#include <gloam/gl.h>

/* These are defined in wingdi.h and we're redefining them. */
#undef wglUseFontBitmaps
#undef wglUseFontOutlines
{%- endif %}
{%- if fs.is_vulkan and external_headers %}

{# ---- External Vulkan headers mode ----------------------------------------
   Include upstream Vulkan-Headers instead of embedding type definitions.
   Uses forward declarations for heavyweight platform types (Win32, Xlib)
   to avoid pulling in large/slow platform headers. -#}
#ifndef VK_NO_PROTOTYPES
#define VK_NO_PROTOTYPES
#endif

#ifndef VULKAN_H_
#include <vulkan/vk_platform.h>
#include <vulkan/vulkan_core.h>
#endif

#if !defined(VULKAN_H_)

#ifdef VK_USE_PLATFORM_ANDROID_KHR
#include <vulkan/vulkan_android.h>
#endif

#ifdef VK_USE_PLATFORM_FUCHSIA
#include <zircon/types.h>
#include <vulkan/vulkan_fuchsia.h>
#endif

#ifdef VK_USE_PLATFORM_IOS_MVK
#include <vulkan/vulkan_ios.h>
#endif

#ifdef VK_USE_PLATFORM_MACOS_MVK
#include <vulkan/vulkan_macos.h>
#endif

#ifdef VK_USE_PLATFORM_METAL_EXT
#include <vulkan/vulkan_metal.h>
#endif

#ifdef VK_USE_PLATFORM_VI_NN
#include <vulkan/vulkan_vi.h>
#endif

#ifdef VK_USE_PLATFORM_WAYLAND_KHR
#include <vulkan/vulkan_wayland.h>
#endif

#ifdef VK_USE_PLATFORM_WIN32_KHR
typedef unsigned long DWORD;
typedef const wchar_t* LPCWSTR;
typedef void* HANDLE;
typedef struct HINSTANCE__* HINSTANCE;
typedef struct HWND__* HWND;
typedef struct HMONITOR__* HMONITOR;
typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
#include <vulkan/vulkan_win32.h>
#endif

#ifdef VK_USE_PLATFORM_XCB_KHR
#include <xcb/xcb.h>
#include <vulkan/vulkan_xcb.h>
#endif

#ifdef VK_USE_PLATFORM_XLIB_KHR
typedef struct _XDisplay Display;
typedef unsigned long Window;
typedef unsigned long VisualID;
#include <vulkan/vulkan_xlib.h>
#endif

#ifdef VK_USE_PLATFORM_DIRECTFB_EXT
#include <directfb.h>
#include <vulkan/vulkan_directfb.h>
#endif

#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
typedef struct _XDisplay Display;
typedef unsigned long RROutput;
#include <vulkan/vulkan_xlib_xrandr.h>
#endif

#ifdef VK_USE_PLATFORM_GGP
#include <ggp_c/vulkan_types.h>
#include <vulkan/vulkan_ggp.h>
#endif

#ifdef VK_USE_PLATFORM_SCREEN_QNX
#include <screen/screen.h>
#include <vulkan/vulkan_screen.h>
#endif

#ifdef VK_USE_PLATFORM_SCI
#include <nvscisync.h>
#include <nvscibuf.h>
#include <vulkan/vulkan_sci.h>
#endif

#ifdef VK_ENABLE_BETA_EXTENSIONS
#include <vulkan/vulkan_beta.h>
#endif

#ifdef VK_USE_PLATFORM_OHOS
#include <vulkan/vulkan_ohos.h>
#endif

#endif /* !defined(VULKAN_H_) */

{%- else %}

#include <stddef.h>
#include <stdint.h>
{% if fs.required_headers | length > 0 %}
{% for hdr in fs.required_headers -%}
#include "{{ hdr }}"
{% endfor -%}
{%- endif %}
{%- if fs.include_type_groups | length > 0 %}
{# Platform / WSI system headers: include-category types whose protection
   guards were inferred at generation time from which extensions require them.
   An empty protect list means the include is unconditional.
   Consecutive types sharing the same guard are coalesced into a single
   #ifdef/#endif block by the resolver. -#}
{% for group in fs.include_type_groups -%}
{{ u.protect_begin(group.protect) -}}
{% for type in group.items -%}
{{ type.raw_c }}
{% endfor -%}
{{ u.protect_end(group.protect) -}}
{% endfor -%}
{%- endif %}
{%- endif %}
#ifdef __cplusplus
extern "C" {
#endif
{%- if fs.is_gl_family %}

/* Calling convention */
#ifndef APIENTRY
#  if defined(GLOAM_PLATFORM_WINDOWS)
#    define APIENTRY __stdcall
#  else
#    define APIENTRY
#  endif
#endif
#ifndef APIENTRYP
#  define APIENTRYP APIENTRY *
#endif
#ifndef GLAPI
#  define GLAPI extern
#endif

/* Calling convention for GL callback function pointers (e.g. debug callbacks,
 * blob cache functions). Piggybacks on APIENTRY if already defined so that
 * code which defines APIENTRY before including this header gets consistent
 * behaviour. Guard against redefinition so multiple gloam headers included
 * in the same translation unit don't conflict.
 */
#ifndef GLOAM_API_PTR
#  ifdef APIENTRY
#    define GLOAM_API_PTR APIENTRY
#  elif defined(GLOAM_PLATFORM_WINDOWS)
#    define GLOAM_API_PTR __stdcall
#  else
#    define GLOAM_API_PTR
#  endif
#endif
#ifndef GLAPIENTRY
#  define GLAPIENTRY GLOAM_API_PTR
#endif
{%- endif %}
{%- if fs.spec_name in ["gl", "gles1", "gles2", "glcore"] %}

/* Forward declarations for OpenCL interop types. */
struct _cl_context;
struct _cl_event;
{%- endif %}
{%- if not (fs.is_vulkan and external_headers) %}
{%- if fs.features | length > 0 %}

/* ---- Version feature guards ----------------------------------------------
 * These mirror the upstream vulkan_core.h / gl.h definitions so that code
 * guarded by e.g. #ifdef GL_VERSION_3_3 compiles correctly against this
 * header.
 */
{% for feat in fs.features -%}
#define {{ feat.full_name }} 1
{% endfor -%}
{%- endif %}
{%- if fs.ext_guard_groups | length > 0 %}
/* ---- Extension compile-time guards ---------------------------------------
 * These mirror the definitions in standard glext.h/gl2ext.h/eglext.h so
 * that code guarded by e.g. #ifdef GL_ARB_draw_indirect compiles correctly
 * against this header.
 */
{% for group in fs.ext_guard_groups -%}
{{- u.protect_begin(group.protect) -}}
{% for ext in group.items -%}
#define {{ ext.name }} 1
{% endfor -%}
{{ u.protect_end(group.protect) -}}
{%- endfor %}
{% endif -%}
{%- if fs.flat_enums | length > 0 -%}
/* ---- Constants ----------------------------------------------------------- */
{% for group in fs.flat_enum_groups -%}
{% if group.protect | length > 0 -%}
#if defined({{ group.protect | join(") && defined(") }})
{% for enum in group.items -%}
#define {{ enum.name }} {{ enum.value }}{% if enum.comment %} /* {{ enum.comment }} */{% endif %}
{% endfor -%}
#endif
{% else -%}
{% for enum in group.items -%}
#define {{ enum.name }} {{ enum.value }}{% if enum.comment %} /* {{ enum.comment }} */{% endif %}
{% endfor -%}
{% endif -%}
{% endfor -%}
{% endif -%}
{%- if fs.enum_groups | length > 0 %}
/* ---- Vulkan enum groups -------------------------------------------------- */
{% for group in fs.enum_groups %}
{%- if group.bitwidth == 64 %}
/* {{ group.name }} — 64-bit; uses enum : uint64_t in C++/C23, static const otherwise. */
#if GLOAM_HAS_ENUM_BASE_TYPE
typedef enum {{ group.name }} : uint64_t {
{%- for val in group.values %}
    {{ val.name }} = {{ val.value }}{% if not loop.last %},{% endif %}{% if val.comment %} /* {{ val.comment }} */{% endif %}
{%- endfor %}
} {{ group.name }};
#else
typedef uint64_t {{ group.name }};
{%- for val in group.values %}
static const {{ group.name }} {{ val.name | rjust(48) }} = {{ val.literal_value | ull }};{% if val.comment %} /* {{ val.comment }} */{% endif %}
{%- endfor %}
#endif

{%- else %}
typedef enum {{ group.name }} {
{%- for val in group.values %}
    {{ val.name }} = {{ val.value }}{% if val.comment %} /* {{ val.comment }} */{% endif %},
{%- endfor %}
    {{ group.name | vk_max_enum_name }} = 0x7FFFFFFF
} {{ group.name }};
{% endif -%}
{% endfor -%}
{% endif %}
/* ---- Types ----------------------------------------------------------------
 * Emitted in topological dependency order. Consecutive types sharing the
 * same platform guard are coalesced into a single #ifdef/#endif block.
 */
{% for group in fs.type_groups -%}
{% if group.protect | length > 0 -%}
#if defined({{ group.protect | join(") && defined(") }})
{% endif -%}
{% for type in group.items -%}
{{ type.raw_c }}
{% if not loop.last %}
{% endif -%}
{% endfor -%}
{% if group.protect | length > 0 -%}
#endif
{% endif -%}
{% if not loop.last %}
{% endif -%}
{% endfor %}

/* ---- PFN typedefs -------------------------------------------------------- */
{% if fs.is_gl_family -%}
{% for group in fs.cmd_pfn_groups -%}
{{- u.protect_begin(group.protect) -}}
{% for cmd in group.items -%}
typedef {{ cmd.return_type }} (APIENTRYP {{ cmd.pfn_type }})({{ cmd.params_str }});
{% endfor -%}
{{ u.protect_end(group.protect) -}}
{% endfor -%}
{% else %}
{% for group in fs.cmd_pfn_groups -%}
{{- u.protect_begin(group.protect) -}}
{% for cmd in group.items -%}
typedef {{ cmd.return_type }} (VKAPI_PTR *{{ cmd.pfn_type }})({{ cmd.params_str }});
{% endfor -%}
{{- u.protect_end(group.protect) -}}
{% endfor -%}
{% endif %}
{%- endif %}

/* ---- Context struct ------------------------------------------------------
 * Three anonymous unions give both indexed (array) and named (struct member)
 * access to the same memory, at zero runtime cost.
 *
 * featArray / extArray: unsigned char flags, one per feature / extension.
 * pfnArray: function pointer slots, one per command.
 *
 * Anonymous structs inside the unions are a C11 / GCC extension; they are
 * universally supported on our target compilers.
 */
typedef struct {{ fs.context_name }} {
    union {
        unsigned char featArray[{{ fs.features | length }}];
        struct {
{%- for feat in fs.features %}
        /* {{ feat.index | rjust(4) }} */ unsigned char {{ feat.short_name }};
{%- endfor %}
        };
    };
{% if fs.extensions | length > 0 %}
    union {
        unsigned char extArray[{{ fs.extensions | length }}];
        struct {
{%- for ext in fs.extensions %}
        /* {{ ext.index | rjust(4) }} */ unsigned char {{ ext.short_name | c_ident }};
{%- endfor %}
        };
    };
{% endif %}
    union {
        void *pfnArray[{{ fs.commands | length }}];
        struct {
{%- for group in fs.cmd_pfn_groups %}
{%- if group.protect | length > 0 %}
#if defined({{ group.protect | join(") && defined(") }})
{%- for cmd in group.items %}
        /* {{ cmd.index | rjust(4) }} */ {{ cmd.pfn_type }} {{ cmd.short_name }};
{%- endfor %}
#else
{%- for cmd in group.items %}
        /* {{ cmd.index | rjust(4) }} */ void *_pad{{ cmd.index }};
{%- endfor %}
#endif
{%- else %}
{%- for cmd in group.items %}
        /* {{ cmd.index | rjust(4) }} */ {{ cmd.pfn_type }} {{ cmd.short_name }};
{%- endfor %}
{%- endif %}
{%- endfor %}
        };
    };

    /* Built-in loader library handle. Set by gloamVulkanInitialize*Context /
     * gloamLoaderLoad*Context when it opens the platform library. If the
     * caller pre-populates this field, the open is skipped and ownership is
     * NOT taken (gloam will not close it). Present on all context types so
     * user code can use a single field name regardless of API.
     */
    void *gloam_loader_handle;

    /* Non-zero if gloam opened the library handle itself and is responsible
     * for closing it in gloamVulkanFinalize / gloamLoaderUnload.
     */
    uint8_t gloam_loader_owns_handle;
{% if fs.is_vulkan %}
    /* The last VkInstance this context loaded entry points from */
    VkInstance vk_loaded_instance;
    /* The last VkDevice this context loaded entry points from */
    VkDevice vk_loaded_device;
    /* Vulkan discovery-path metadata — used by gloamLoaderLoadVulkanContext to make
     * repeated calls additive without re-enumerating already-cached scopes.
     */
    uint32_t vk_instance_version;    /* cached EnumerateInstanceVersion result        */
    uint32_t vk_device_version;      /* cached GetPhysicalDeviceProperties.apiVersion */
    uint8_t  vk_found_instance_exts; /* set once instance extensions enumerated       */
    uint8_t  vk_found_device_exts;   /* set once device extensions enumerated         */
{% endif -%}
} {{ fs.context_name }};

/* Global context instance — a value, not a pointer, so the compiler knows
 * its address is fixed and does not re-load it on every access.
 */
extern {{ fs.context_name }} gloam_{{ fs.spec_name }}_context;

/* ---- Feature presence macros --------------------------------------------
 * Test whether a versioned feature was detected at load time.
 */
{%- for feat in fs.features %}
#define GLOAM_{{ feat.full_name }} (gloam_{{ fs.spec_name }}_context.{{ feat.short_name }})
{%- endfor %}

/* ---- Extension presence macros ------------------------------------------ */
{% for group in fs.ext_guard_groups %}
{{- u.protect_begin(group.protect) -}}
{% for ext in group.items -%}
#define GLOAM_{{ ext.name }} (gloam_{{ fs.spec_name }}_context.{{ ext.short_name | c_ident }})
{% endfor -%}
{{- u.protect_end(group.protect) -}}
{%- endfor %}

/* ---- Dispatch ------------------------------------------------------------ */
{% if fs.is_vulkan -%}
{# Vulkan: force-inlined function wrappers that dispatch through the global
   context struct. Unlike #define macros, these don't pollute the preprocessor
   namespace (avoids collisions with VMA, etc.). #}
{% for group in fs.cmd_pfn_groups -%}
{% if group.protect | length > 0 -%}
#if defined({{ group.protect | join(") && defined(") }})
{% endif -%}
{% for cmd in group.items -%}
GLOAM_FORCE_INLINE {{ cmd.return_type }} {{ cmd.name }}({{ cmd.params_str }}) {
    {% if cmd.return_type != "void" %}return {% endif %}gloam_{{ fs.spec_name }}_context.{{ cmd.short_name }}({{ cmd.params | map(attribute="name") | join(", ") }});
}
{% endfor -%}
{% if group.protect | length > 0 -%}
#endif
{% endif -%}
{% endfor -%}
{% else -%}
{# GL/EGL/GLX/WGL: macro dispatch with IntelliSense prototypes for IDE support. #}
#ifdef __INTELLISENSE__
{% for group in fs.cmd_pfn_groups -%}
{% if group.protect | length > 0 -%}
#if defined({{ group.protect | join(") && defined(") }})
{% endif -%}
{% for cmd in group.items -%}
{{ cmd.return_type }} {{ cmd.name }}({{ cmd.params_str }});
{% endfor -%}
{% if group.protect | length > 0 -%}
#endif
{% endif -%}
{% endfor -%}
#else
{% for group in fs.cmd_pfn_groups -%}
{% if group.protect | length > 0 -%}
#if defined({{ group.protect | join(") && defined(") }})
{% endif -%}
{% for cmd in group.items -%}
#define {{ cmd.name }} (gloam_{{ fs.spec_name }}_context.{{ cmd.short_name }})
{% endfor -%}
{% if group.protect | length > 0 -%}
#endif
{% endif -%}
{% endfor -%}
#endif /* __INTELLISENSE__ */
{% endif -%}

/* ---- API declarations ---------------------------------------------------- */

#ifndef GLOAM_DEFINED_CALLBACK_TYPES_
#define GLOAM_DEFINED_CALLBACK_TYPES_
/* Opaque function pointer type — the common return type for all load
 * callbacks. Callers cast to the specific PFN type they need.
 */
typedef void (*GloamAPIProc)(void);

/* Load function pointer type (GL / EGL / GLX / WGL). */
typedef GloamAPIProc (*GloamLoadFunc)(const char *name);
#endif
{% for api in fs.apis -%}
{%- if fs.spec_name in ["gl", "gles1", "gles2", "glcore"] %}
int gloamLoad{{ api | api_display }}Context({{ u.ctx_arg(', ') }}GloamLoadFunc getProcAddr);
int gloamLoad{{ api | api_display }}(GloamLoadFunc getProcAddr);
{%- elif fs.spec_name == "egl" %}
int gloamLoad{{ api | api_display }}Context({{ u.ctx_arg(', ') }}EGLDisplay display, GloamLoadFunc getProcAddr);
int gloamLoad{{ api | api_display }}(EGLDisplay display, GloamLoadFunc getProcAddr);
{%- elif fs.spec_name == "glx" %}
int gloamLoad{{ api | api_display }}Context({{ u.ctx_arg(', ') }}Display *display, int screen, GloamLoadFunc getProcAddr);
int gloamLoad{{ api | api_display }}(Display *display, int screen, GloamLoadFunc getProcAddr);
{%- elif fs.spec_name == "wgl" %}
int gloamLoad{{ api | api_display }}Context({{ u.ctx_arg(', ') }}HDC hdc, GloamLoadFunc getProcAddr);
int gloamLoad{{ api | api_display }}(HDC hdc, GloamLoadFunc getProcAddr);
{%- elif fs.spec_name == "vk" %}
/* ---- Vulkan enabled API (Volk-like) ----------------------------------------
 * Phased loading: Initialize → LoadInstance → LoadDevice.
 * The caller owns extension discovery and tells gloam what was enabled.
 *
 * Phase 0 — Initialize: open libvulkan and load the handful of Global-scope
 * PFNs needed to create an instance (vkCreateInstance, vkEnumerateInstance*).
 * If library_handle is non-NULL, use it without taking ownership; if NULL,
 * dlopen the platform default and take ownership.
 *
 * Phase 1 — LoadInstance: load Global + Instance-scope PFNs for core features
 * and enabled instance extensions. Set featArray from api_version
 * (VK_MAKE_API_VERSION or VK_API_VERSION_x_y). Set extArray for enabled
 * instance extensions. Resolve aliases.
 *
 * Phase 1.5 (optional) — LoadPhysicalDeviceExtension(s): pre-load
 * Instance-scope PFNs for device extensions the application wants to query
 * before creating a VkDevice (e.g. vkGetPhysicalDeviceFragmentShadingRatesKHR
 * from VK_KHR_fragment_shading_rate). Does NOT set extArray.
 *
 * Phase 2 — LoadDevice: load PFNs for enabled device extensions (all scopes).
 * Device-scope commands use vkGetDeviceProcAddr for the fast path; Instance-
 * scope commands in device extensions use vkGetInstanceProcAddr. Update
 * featArray from the device's api_version. Set extArray for enabled device
 * extensions. Resolve aliases.
 *
 * Finalize: close library handle if gloam owns it, zero the context.
 */
{% if loader -%}
int  gloamVulkanInitializeContext({{ u.ctx_arg(', ') }}void *library_handle);
int  gloamVulkanInitialize(void *library_handle);
{% endif -%}
void gloamVulkanInitializeCustomContext({{ u.ctx_arg(', ') }}PFN_vkGetInstanceProcAddr getInstanceProcAddr);
void gloamVulkanInitializeCustom(PFN_vkGetInstanceProcAddr getInstanceProcAddr);
uint32_t gloamVulkanGetInstanceVersionContext({{ u.ctx_arg() }});
uint32_t gloamVulkanGetInstanceVersion(void);
int  gloamVulkanLoadInstanceContext({{ u.ctx_arg(', ') }}VkInstance instance, uint32_t api_version, uint32_t num_instance_extensions, const char *const *instance_extensions);
int  gloamVulkanLoadInstance(VkInstance instance, uint32_t api_version, uint32_t num_instance_extensions, const char *const *instance_extensions);
VkInstance gloamVulkanGetLoadedInstanceContext({{ u.ctx_arg() }});
VkInstance gloamVulkanGetLoadedInstance(void);
void gloamVulkanLoadPhysicalDeviceExtensionContext({{ u.ctx_arg(', ') }}const char *device_extension);
void gloamVulkanLoadPhysicalDeviceExtension(const char *device_extension);
void gloamVulkanLoadPhysicalDeviceExtensionsContext({{ u.ctx_arg(', ') }}uint32_t num_device_extensions, const char *const *device_extensions);
void gloamVulkanLoadPhysicalDeviceExtensions(uint32_t num_device_extensions, const char *const *device_extensions);
int  gloamVulkanLoadDeviceContext({{ u.ctx_arg(', ') }}VkDevice device, VkPhysicalDevice physical_device, uint32_t num_device_extensions, const char *const *device_extensions);
int  gloamVulkanLoadDevice(VkDevice device, VkPhysicalDevice physical_device, uint32_t num_device_extensions, const char *const *device_extensions);
VkDevice gloamVulkanGetLoadedDeviceContext({{ u.ctx_arg() }});
VkDevice gloamVulkanGetLoadedDevice(void);
void gloamVulkanFinalizeContext({{ u.ctx_arg() }});
void gloamVulkanFinalize(void);
{% endif %}
{% endfor -%}

{%- if loader -%}
/* Built-in loader: opens the platform library if needed and calls the
 * appropriate load function for you. Non-Vulkan loaders call the detection-
 * based gloamLoad* functions. Vulkan loaders handle all extension detection
 * and PFN loading internally.
 * Each Load function may be called multiple times (additive).
 */
{%- for api in fs.apis %}
{%- if fs.spec_name in ["gl", "gles1", "gles2", "glcore"] %}
int  gloamLoaderLoad{{ api | api_display }}Context({{ u.ctx_arg() }});
int  gloamLoaderLoad{{ api | api_display }}(void);
void gloamLoaderUnload{{ api | api_display }}Context({{ u.ctx_arg() }});
void gloamLoaderUnload{{ api | api_display }}(void);
void gloamLoaderReset{{ api | api_display }}Context({{ u.ctx_arg() }});
void gloamLoaderReset{{ api | api_display }}(void);
{%- elif fs.spec_name == "egl" %}
int  gloamLoaderLoad{{ api | api_display }}Context({{ u.ctx_arg(', ') }}EGLDisplay display);
int  gloamLoaderLoad{{ api | api_display }}(EGLDisplay display);
void gloamLoaderUnload{{ api | api_display }}Context({{ u.ctx_arg() }});
void gloamLoaderUnload{{ api | api_display }}(void);
void gloamLoaderReset{{ api | api_display }}Context({{ u.ctx_arg() }});
void gloamLoaderReset{{ api | api_display }}(void);
{%- elif fs.spec_name == "glx" %}
int  gloamLoaderLoad{{ api | api_display }}Context({{ u.ctx_arg(', ') }}Display *display, int screen);
int  gloamLoaderLoad{{ api | api_display }}(Display *display, int screen);
void gloamLoaderUnload{{ api | api_display }}Context({{ u.ctx_arg() }});
void gloamLoaderUnload{{ api | api_display }}(void);
void gloamLoaderReset{{ api | api_display }}Context({{ u.ctx_arg() }});
void gloamLoaderReset{{ api | api_display }}(void);
{%- elif fs.spec_name == "wgl" %}
int  gloamLoaderLoad{{ api | api_display }}Context({{ u.ctx_arg(', ') }}HDC hdc);
int  gloamLoaderLoad{{ api | api_display }}(HDC hdc);
void gloamLoaderUnload{{ api | api_display }}Context({{ u.ctx_arg() }});
void gloamLoaderUnload{{ api | api_display }}(void);
void gloamLoaderReset{{ api | api_display }}Context({{ u.ctx_arg() }});
void gloamLoaderReset{{ api | api_display }}(void);
{%- elif fs.spec_name == "vk" %}
int  gloamLoaderLoadVulkanContext({{ u.ctx_arg(', ') }}VkInstance instance, VkPhysicalDevice physical_device, VkDevice device);
int  gloamLoaderLoadVulkan(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device);
void gloamLoaderUnloadVulkanContext({{ u.ctx_arg() }});
void gloamLoaderUnloadVulkan(void);
void gloamLoaderResetVulkanContext({{ u.ctx_arg() }});
void gloamLoaderResetVulkan(void);
{%- endif %}
{% endfor -%}
{% endif %}
#ifdef __cplusplus
}
#endif
{% if fs.spec_name == "glx" %}
#endif /* GLOAM_PLATFORM_LINUX */
{% elif fs.spec_name == "wgl" %}
#endif /* GLOAM_PLATFORM_WINDOWS */
{% endif %}
#endif /* GLOAM_{{ guard }} */
