Skip to content

tonis2/Vulkan.c3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

471 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vulkan.c3

Vulkan bindings for the C3 programming language with idiomatic C3 error handling and builder patterns for easy Vulkan development.

Features

  • Complete Vulkan API Coverage - Bindings for Vulkan API versions 1.0 through 1.4
  • Idiomatic C3 Error Handling - Vulkan commands use C3's error handling mechanisms
  • Builder Pattern - Auto-generated builder pattern for easy Vulkan struct creation
  • Cross-Platform - Supports Windows, Linux (Wayland/X11), and macOS
  • Working Example - Includes a complete 3D cube example to get you started

Prerequisites

Before using this library, you need:

  1. C3 Compiler - Install the latest version of the C3 compiler
  2. Vulkan SDK - Download and install the Vulkan SDK for your platform

Running the Example

# Linux
c3c run cube

# Windows
c3c run cube-win

# macOS (adjust path as needed)
c3c run cube -z -rpath -z /Users/yourusername/VulkanSDK/macOS/lib

Linux

  1. Install Vulkan SDK:

    # Ubuntu/Debian
    sudo apt install vulkan-tools vulkan-validationlayers-dev spirv-tools
    
    # Or download from LunarG website and follow their instructions
  2. Choose Display Server (Wayland or X11): Edit project.json and set the appropriate feature:

    "features": ["WAYLAND"]  // For Wayland
    // or
    "features": ["X11"]      // For X11

Windows

  1. Install Vulkan SDK: Download from LunarG Vulkan SDK

  2. Add Vulkan to PATH: Ensure VULKAN_SDK environment variable is set

  3. Cross-compilation from Linux: If developing on Linux but targeting Windows, the cube-win target includes the necessary Windows SDK configuration.

macOS

  1. Install C3: Follow the macOS installation guide

  2. Install Vulkan SDK: Download Vulkan SDK for macOS

  3. Run the example with the Vulkan library path:

    # Replace /path/to/VulkanSDK with your actual SDK path
    c3c run cube -z -rpath -z /Users/yourusername/VulkanSDK/macOS/lib

Controls:

  • Mouse: Click and drag to rotate the camera
  • Scroll: Zoom in/out

Using the Library in Your Project

Option 1: Using the Pre-built Library

  1. Build the library file:

    Download the prebuilt library from here

    Or build manually.

    c3c build zip --trust=full

    This creates vulkan.c3l in the project root.

  2. Copy vulkan.c3l to your project's library directory (e.g., ./libs/)

  3. Update your project.json:

    {
      "dependency-search-paths": ["./libs"],
      "dependencies": ["vulkan"]
    }
  4. Use in your code:

    import vk;
    
    fn void main() {
        // Create Vulkan instance
        ApplicationInfo info = {
          .pApplicationName = "TEST",
          .pEngineName = "Super engine",
          .applicationVersion = vk::@makeApiVersion(0,1,0,0),
          .engineVersion = vk::@makeApiVersion(0,1,0,0),
          .apiVersion = vk::@makeApiVersion(0,1,3,0)
        };
    
        InstanceCreateInfo instanceInfo = vk::instanceCreateInfo()
        .setApplicationInfo(&info)
        .setFlags(env::os_is_darwin() ? vk::INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR : 0)
        .setEnabledExtensionNames(extensions.array_view());
       }
    }

Building the Bindings

If you want to regenerate the Vulkan bindings from the official XML specification:

  1. Run the build script:
    sh build.sh

License

This project is licensed under the terms found in the LICENSE file.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Resources

About

Vulkan bindings for C3 language

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages