55#define GLOAM_{{ guard }}
66{# ---- System-header conflict guards ---------------------------------------
77 These prevent including both the platform/system GL or Vulkan headers and
8- this gloam header, which would cause duplicate declarations. Using
8+ this gloam header, which would cause duplicate declarations. Using
99 reserved identifiers (double-underscore prefixed) requires suppressing the
1010 clang warning for that specific pragma block. #}
1111{% - if fs .spec_name in ["gl" , "gles1" , "gles2" , "glcore" ] %}
@@ -238,10 +238,11 @@ extern "C" {
238238#endif
239239
240240/* Calling convention for GL callback function pointers (e.g. debug callbacks,
241- blob cache functions). Piggybacks on APIENTRY if already defined so that
242- code which defines APIENTRY before including this header gets consistent
243- behaviour. Guard against redefinition so multiple gloam headers included
244- in the same translation unit don't conflict. */
241+ * blob cache functions). Piggybacks on APIENTRY if already defined so that
242+ * code which defines APIENTRY before including this header gets consistent
243+ * behaviour. Guard against redefinition so multiple gloam headers included
244+ * in the same translation unit don't conflict.
245+ */
245246#ifndef GLOAM_API_PTR
246247# ifdef APIENTRY
247248# define GLOAM_API_PTR APIENTRY
@@ -265,18 +266,20 @@ struct _cl_event;
265266{% - if not (fs .is_vulkan and external_headers ) -%}
266267{% - if fs .features | length > 0 -%}
267268/* ---- Version feature guards ----------------------------------------------
268- These mirror the upstream vulkan_core.h / gl.h definitions so that code
269- guarded by e.g. #ifdef GL_VERSION_3_3 compiles correctly against this
270- header. */
269+ * These mirror the upstream vulkan_core.h / gl.h definitions so that code
270+ * guarded by e.g. #ifdef GL_VERSION_3_3 compiles correctly against this
271+ * header.
272+ */
271273{% for feat in fs .features -%}
272274#define {{ feat.full_name }} 1
273275{% endfor -%}
274276{% endif -%}
275277{% - if fs .ext_guard_groups | length > 0 %}
276278/* ---- Extension compile-time guards ---------------------------------------
277- These mirror the definitions in standard glext.h/gl2ext.h/eglext.h so
278- that code guarded by e.g. #ifdef GL_ARB_draw_indirect compiles correctly
279- against this header. */
279+ * These mirror the definitions in standard glext.h/gl2ext.h/eglext.h so
280+ * that code guarded by e.g. #ifdef GL_ARB_draw_indirect compiles correctly
281+ * against this header.
282+ */
280283{% for group in fs .ext_guard_groups -%}
281284{{- u.protect_begin(group.protect) -}}
282285{% for ext in group .items -%}
@@ -330,8 +333,9 @@ typedef enum {{ group.name }} {
330333{% endfor -%}
331334{% endif %}
332335/* ---- Types ----------------------------------------------------------------
333- Emitted in topological dependency order. Consecutive types sharing the
334- same platform guard are coalesced into a single #ifdef/#endif block. */
336+ * Emitted in topological dependency order. Consecutive types sharing the
337+ * same platform guard are coalesced into a single #ifdef/#endif block.
338+ */
335339{% for group in fs .type_groups -%}
336340{% if group .protect | length > 0 -%}
337341#if defined({{ group.protect | join(") && defined(") }})
@@ -369,14 +373,15 @@ typedef {{ cmd.return_type }} (VKAPI_PTR *{{ cmd.pfn_type }})({{ cmd.params_str
369373{% - endif %}
370374
371375/* ---- Context struct ------------------------------------------------------
372- Three anonymous unions give both indexed (array) and named (struct member)
373- access to the same memory, at zero runtime cost.
374-
375- featArray / extArray: unsigned char flags, one per feature / extension.
376- pfnArray: function pointer slots, one per command.
377-
378- Anonymous structs inside the unions are a C11 / GCC extension; they are
379- universally supported on our target compilers. */
376+ * Three anonymous unions give both indexed (array) and named (struct member)
377+ * access to the same memory, at zero runtime cost.
378+ *
379+ * featArray / extArray: unsigned char flags, one per feature / extension.
380+ * pfnArray: function pointer slots, one per command.
381+ *
382+ * Anonymous structs inside the unions are a C11 / GCC extension; they are
383+ * universally supported on our target compilers.
384+ */
380385typedef struct {{ fs.context_name }} {
381386 union {
382387 unsigned char featArray[{{ fs.features | length }}];
@@ -418,22 +423,27 @@ typedef struct {{ fs.context_name }} {
418423{% - endfor %}
419424 };
420425 };
421- /* Built-in loader library handle. Set by gloamVulkanInitialize*Context /
422- gloamLoaderLoad*Context when it opens the platform library. If the
423- caller pre-populates this field, the open is skipped and ownership is
424- NOT taken (gloam will not close it). Present on all context types so
425- user code can use a single field name regardless of API. */
426+
427+ /* Built-in loader library handle. Set by gloamVulkanInitialize*Context /
428+ * gloamLoaderLoad*Context when it opens the platform library. If the
429+ * caller pre-populates this field, the open is skipped and ownership is
430+ * NOT taken (gloam will not close it). Present on all context types so
431+ * user code can use a single field name regardless of API.
432+ */
426433 void *gloam_loader_handle;
434+
427435 /* Non-zero if gloam opened the library handle itself and is responsible
428- for closing it in gloamVulkanFinalize / gloamLoaderUnload. */
436+ * for closing it in gloamVulkanFinalize / gloamLoaderUnload.
437+ */
429438 uint8_t gloam_loader_owns_handle;
430439{% if fs .is_vulkan %}
431440 /* The last VkInstance this context loaded entry points from */
432441 VkInstance vk_loaded_instance;
433442 /* The last VkDevice this context loaded entry points from */
434443 VkDevice vk_loaded_device;
435444 /* Vulkan discovery-path metadata — used by gloamLoaderLoadVulkanContext to make
436- repeated calls additive without re-enumerating already-cached scopes. */
445+ * repeated calls additive without re-enumerating already-cached scopes.
446+ */
437447 uint32_t vk_instance_version; /* cached EnumerateInstanceVersion result */
438448 uint32_t vk_device_version; /* cached GetPhysicalDeviceProperties.apiVersion */
439449 uint8_t vk_found_instance_exts; /* set once instance extensions enumerated */
@@ -442,11 +452,13 @@ typedef struct {{ fs.context_name }} {
442452} {{ fs.context_name }};
443453
444454/* Global context instance — a value, not a pointer, so the compiler knows
445- its address is fixed and does not re-load it on every access. */
455+ * its address is fixed and does not re-load it on every access.
456+ */
446457extern {{ fs.context_name }} gloam_{{ fs.spec_name }}_context;
447458
448459/* ---- Feature presence macros --------------------------------------------
449- Test whether a versioned feature was detected at load time. */
460+ * Test whether a versioned feature was detected at load time.
461+ */
450462{% - for feat in fs .features %}
451463#define GLOAM_{{ feat.full_name }} (gloam_{{ fs.spec_name }}_context.{{ feat.short_name }})
452464{% - endfor %}
@@ -463,7 +475,7 @@ extern {{ fs.context_name }} gloam_{{ fs.spec_name }}_context;
463475/* ---- Dispatch ------------------------------------------------------------ */
464476{% if fs .is_vulkan -%}
465477{# Vulkan: force-inlined function wrappers that dispatch through the global
466- context struct. Unlike #define macros, these don't pollute the preprocessor
478+ context struct. Unlike #define macros, these don't pollute the preprocessor
467479 namespace (avoids collisions with VMA, etc.). #}
468480{% for group in fs .cmd_pfn_groups -%}
469481{% if group .protect | length > 0 -%}
@@ -512,7 +524,8 @@ GLOAM_FORCE_INLINE {{ cmd.return_type }} {{ cmd.name }}({{ cmd.params_str }}) {
512524#ifndef GLOAM_DEFINED_CALLBACK_TYPES_
513525#define GLOAM_DEFINED_CALLBACK_TYPES_
514526/* Opaque function pointer type — the common return type for all load
515- callbacks. Callers cast to the specific PFN type they need. */
527+ * callbacks. Callers cast to the specific PFN type they need.
528+ */
516529typedef void (*GloamAPIProc)(void);
517530
518531/* Load function pointer type (GL / EGL / GLX / WGL). */
@@ -533,31 +546,32 @@ int gloamLoad{{ api | api_display }}Context({{ u.ctx_arg(', ') }}HDC hdc, GloamL
533546int gloamLoad{{ api | api_display }}(HDC hdc, GloamLoadFunc getProcAddr);
534547{% - elif fs .spec_name == "vk" %}
535548/* ---- Vulkan enabled API (Volk-like) ----------------------------------------
536- Phased loading: Initialize → LoadInstance → LoadDevice.
537- The caller owns extension discovery and tells gloam what was enabled.
538-
539- Phase 0 — Initialize: open libvulkan and load the handful of Global-scope
540- PFNs needed to create an instance (vkCreateInstance, vkEnumerateInstance*).
541- If library_handle is non-NULL, use it without taking ownership; if NULL,
542- dlopen the platform default and take ownership.
543-
544- Phase 1 — LoadInstance: load Global + Instance-scope PFNs for core features
545- and enabled instance extensions. Set featArray from api_version
546- (VK_MAKE_API_VERSION or VK_API_VERSION_x_y). Set extArray for enabled
547- instance extensions. Resolve aliases.
548-
549- Phase 1.5 (optional) — LoadPhysicalDeviceExtension(s): pre-load
550- Instance-scope PFNs for device extensions the application wants to query
551- before creating a VkDevice (e.g. vkGetPhysicalDeviceFragmentShadingRatesKHR
552- from VK_KHR_fragment_shading_rate). Does NOT set extArray.
553-
554- Phase 2 — LoadDevice: load PFNs for enabled device extensions (all scopes).
555- Device-scope commands use vkGetDeviceProcAddr for the fast path; Instance-
556- scope commands in device extensions use vkGetInstanceProcAddr. Update
557- featArray from the device's api_version. Set extArray for enabled device
558- extensions. Resolve aliases.
559-
560- Finalize: close library handle if gloam owns it, zero the context. */
549+ * Phased loading: Initialize → LoadInstance → LoadDevice.
550+ * The caller owns extension discovery and tells gloam what was enabled.
551+ *
552+ * Phase 0 — Initialize: open libvulkan and load the handful of Global-scope
553+ * PFNs needed to create an instance (vkCreateInstance, vkEnumerateInstance*).
554+ * If library_handle is non-NULL, use it without taking ownership; if NULL,
555+ * dlopen the platform default and take ownership.
556+ *
557+ * Phase 1 — LoadInstance: load Global + Instance-scope PFNs for core features
558+ * and enabled instance extensions. Set featArray from api_version
559+ * (VK_MAKE_API_VERSION or VK_API_VERSION_x_y). Set extArray for enabled
560+ * instance extensions. Resolve aliases.
561+ *
562+ * Phase 1.5 (optional) — LoadPhysicalDeviceExtension(s): pre-load
563+ * Instance-scope PFNs for device extensions the application wants to query
564+ * before creating a VkDevice (e.g. vkGetPhysicalDeviceFragmentShadingRatesKHR
565+ * from VK_KHR_fragment_shading_rate). Does NOT set extArray.
566+ *
567+ * Phase 2 — LoadDevice: load PFNs for enabled device extensions (all scopes).
568+ * Device-scope commands use vkGetDeviceProcAddr for the fast path; Instance-
569+ * scope commands in device extensions use vkGetInstanceProcAddr. Update
570+ * featArray from the device's api_version. Set extArray for enabled device
571+ * extensions. Resolve aliases.
572+ *
573+ * Finalize: close library handle if gloam owns it, zero the context.
574+ */
561575{% if loader -%}
562576int gloamVulkanInitializeContext({{ u.ctx_arg(', ') }}void *library_handle);
563577int gloamVulkanInitialize(void *library_handle);
@@ -585,10 +599,11 @@ void gloamVulkanFinalize(void);
585599
586600{% - if loader -%}
587601/* Built-in loader: opens the platform library if needed and calls the
588- appropriate load function for you. Non-Vulkan loaders call the detection-
589- based gloamLoad* functions. Vulkan loaders handle all extension detection
590- and PFN loading internally.
591- Each Load function may be called multiple times (additive). */
602+ * appropriate load function for you. Non-Vulkan loaders call the detection-
603+ * based gloamLoad* functions. Vulkan loaders handle all extension detection
604+ * and PFN loading internally.
605+ * Each Load function may be called multiple times (additive).
606+ */
592607{% - for api in fs .apis %}
593608{% - if fs .spec_name in ["gl" , "gles1" , "gles2" , "glcore" ] %}
594609int gloamLoaderLoad{{ api | api_display }}Context({{ u.ctx_arg() }});
0 commit comments