55from .src .translator .ast import ASTNode
66from .src .backend .DirectX import *
77from .src .backend .Metal import *
8- # from .src.backend.Opengl import *
8+ from .src .backend .Opengl import *
99
10- def translate (file_path : str , backend : str = "cgl" ) -> str :
10+
11+ def translate (file_path : str , backend : str = "crossgl" ) -> str :
1112 backend = backend .lower ()
1213
13- with open (file_path , 'r' ) as file :
14+ with open (file_path , "r" ) as file :
1415 shader_code = file .read ()
1516
1617 # Determine the input shader type based on the file extension
1718 if file_path .endswith (".cgl" ):
18- from .src .translator .lexer import Lexer
19- from .src .translator .parser import Parser
2019 lexer = Lexer (shader_code )
2120 parser = Parser (lexer .tokens )
2221 elif file_path .endswith (".hlsl" ):
@@ -26,9 +25,8 @@ def translate(file_path: str, backend: str = "cgl") -> str:
2625 lexer = MetalLexer (shader_code )
2726 parser = MetalParser (lexer .tokens )
2827 elif file_path .endswith (".glsl" ):
29- from .src .backend .Opengl import Lexer , Parser
30- lexer = Lexer (shader_code )
31- parser = Parser (lexer .tokens )
28+ lexer = GLSLLexer (shader_code )
29+ parser = GLSLParser (lexer .tokens )
3230 else :
3331 raise ValueError (f"Unsupported shader file type: { file_path } " )
3432
@@ -53,10 +51,11 @@ def translate(file_path: str, backend: str = "cgl") -> str:
5351 elif file_path .endswith (".metal" ):
5452 codegen = MetalToCrossGLConverter ()
5553 elif file_path .endswith (".glsl" ):
56- from .src .backend .Opengl import CrossglCodeGen as GLSLToCrossGLConverter
5754 codegen = GLSLToCrossGLConverter ()
5855 else :
5956 raise ValueError (f"Reverse translation not supported for: { file_path } " )
6057 return codegen .generate (ast )
6158 else :
62- raise ValueError (f"Unsupported translation scenario: { file_path } to { backend } " )
59+ raise ValueError (
60+ f"Unsupported translation scenario: { file_path } to { backend } "
61+ )
0 commit comments