Skip to content

Commit

Permalink
fix texture2D issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ferriarnus committed Oct 20, 2024
1 parent 27dc6b4 commit bc38ac8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/taumc/glsl/ExpressionRenamer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/taumc/glsl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/taumc/glsl/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, GLSLParser.Single_declarationContext> findQualifiers(GLSLParser.Translation_unitContext root, int type) {
Expand Down

0 comments on commit bc38ac8

Please sign in to comment.