Public API

Public package interface for CrossGL Translator.

High-level translation API and command-line entry point for CrossGL Translator.

crosstl._crosstl.main()[source]

Command-line entry point for CrossGL translation.

crosstl._crosstl.translate(file_path, backend='cgl', save_shader=None, format_output=True)[source]

Translate a shader file to another language.

Parameters:
  • file_path (str) – The path to the shader file

  • backend (str, optional) – The target language to translate to. Defaults to “cgl”.

  • save_shader (str, optional) – The path to save the translated shader. Defaults to None.

  • format_output (bool, optional) – Whether to format the generated code. Defaults to True.

Returns:

The translated shader code

Return type:

str

Formatting helpers for generated shader and compute source code.

class crosstl.formatter.CodeFormatter(clang_format_path=None, spirv_tools_path=None)[source]

Bases: object

Formats shader code using appropriate external tools

detect_language(file_path)[source]

Detect shader language from file extension

format_code(code, language=None, file_path=None)[source]

Format source text for a shader language, falling back to input text.

validate_spirv(code)[source]

Validate SPIR-V code.

class crosstl.formatter.ShaderLanguage(value)[source]

Bases: Enum

Supported shader languages for formatting

crosstl.formatter.format_code(code, language=None, file_path=None)[source]

Format code using the CodeFormatter

This is a convenience function used by format_shader_code

Parameters:
  • code – The shader code to format

  • language – ShaderLanguage enum or string

  • file_path – Optional file path for language detection

Returns:

Formatted code string

crosstl.formatter.format_file(file_path, language=None)[source]

Format a shader file in-place.

crosstl.formatter.format_shader_code(code, backend, output_path=None)[source]

Format shader code based on backend.