From bc38ac8c72ffceb3c4a68af754022713bce6812d Mon Sep 17 00:00:00 2001 From: ferriarnus <61201275+ferriarnus@users.noreply.github.com> Date: Sun, 20 Oct 2024 23:24:36 +0200 Subject: [PATCH] fix texture2D issue --- src/main/java/org/taumc/glsl/ExpressionRenamer.java | 8 ++++++++ src/main/java/org/taumc/glsl/Main.java | 4 +++- src/main/java/org/taumc/glsl/Util.java | 6 +++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/taumc/glsl/ExpressionRenamer.java b/src/main/java/org/taumc/glsl/ExpressionRenamer.java index edabfab..77c37f8 100644 --- a/src/main/java/org/taumc/glsl/ExpressionRenamer.java +++ b/src/main/java/org/taumc/glsl/ExpressionRenamer.java @@ -38,4 +38,12 @@ public void enterFunction_prototype(GLSLParser.Function_prototypeContext ctx) { handleIdentifier(ctx.IDENTIFIER()); } } + + + @Override + public void enterType_specifier_nonarray(GLSLParser.Type_specifier_nonarrayContext ctx) { + if (ctx.TEXTURE2D() != null) { + handleIdentifier(ctx.TEXTURE2D()); + } + } } diff --git a/src/main/java/org/taumc/glsl/Main.java b/src/main/java/org/taumc/glsl/Main.java index 649e33c..1dc692a 100644 --- a/src/main/java/org/taumc/glsl/Main.java +++ b/src/main/java/org/taumc/glsl/Main.java @@ -42,12 +42,14 @@ public static void main(String[] args) throws Exception { Util.replaceExpression(translationUnit, "vartest", "unint(5)"); Util.removeUnusedFunctions(translationUnit); Util.rewriteStructArrays(translationUnit); + Util.renameFunctionCall(translationUnit, "texture2D", "texture"); + System.out.println(getFormattedShader(translationUnit)); ShaderViewerGUI.display(parser, translationUnit); } - private static String getFormattedShader(ParseTree tree) { + public static String getFormattedShader(ParseTree tree) { StringBuilder sb = new StringBuilder(); getFormattedShader(tree, sb); return sb.toString(); diff --git a/src/main/java/org/taumc/glsl/Util.java b/src/main/java/org/taumc/glsl/Util.java index 992abe2..d66415f 100644 --- a/src/main/java/org/taumc/glsl/Util.java +++ b/src/main/java/org/taumc/glsl/Util.java @@ -174,10 +174,10 @@ public static void initialize(GLSLParser.Translation_unitContext root, GLSLParse } } - public static void makeOutDeclaration(GLSLParser.Translation_unitContext root, GLSLParser.Single_declarationContext inDeclarationContext) { - String insert = inDeclarationContext.getText() + ";"; + public static void makeOutDeclaration(GLSLParser.Translation_unitContext root, GLSLParser.Single_declarationContext inDeclarationContext, String name) { + String insert = Main.getFormattedShader(inDeclarationContext.fully_specified_type()) + name + ";"; //TODO, find a different way to make the out declaration insert = insert.replaceFirst("in", "out"); - Util.prependMain(root, insert); + Util.injectVariable(root, insert); } public static Map findQualifiers(GLSLParser.Translation_unitContext root, int type) {