-
-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for drawing to multiple render targets #6657
Changes from all commits
4b25f71
2eecb8a
17e4860
aef780c
b8560d1
f90f671
c14f4f7
89d48b4
ef86368
e288020
d6e193e
05edeee
0c021d2
07f5b76
7eb40fc
0710653
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,6 +193,7 @@ public static enum ShaderType { | |
private static final Pattern regexVersionStringPattern = Pattern.compile("^\\h*#\\h*version\\h+(?<version>\\d+)(\\h+(?<profile>\\S+))?\\h*\\n"); | ||
private static final Pattern regexPrecisionKeywordPattern = Pattern.compile("(?<keyword>precision)\\s+(?<precision>lowp|mediump|highp)\\s+(?<type>float|int)\\s*;"); | ||
private static final Pattern regexUniformKeywordPattern = Pattern.compile("((?<keyword>uniform)\\s+|(?<layout>layout\\s*\\(.*\\n*.*\\)\\s*)\\s+|(?<precision>lowp|mediump|highp)\\s+)*(?<type>\\S+)\\s+(?<identifier>\\S+)\\s*(?<any>.*)\\s*;"); | ||
private static final Pattern regexFragDataArrayPattern = Pattern.compile("gl_FragData\\[(?<index>\\d+)\\]"); | ||
|
||
private static final String[][] vsKeywordReps = {{"varying", "out"}, {"attribute", "in"}, {"texture2D", "texture"}, {"textureCube", "texture"}}; | ||
private static final String[][] fsKeywordReps = {{"varying", "in"}, {"texture2D", "texture"}, {"textureCube", "texture"}}; | ||
|
@@ -203,7 +204,7 @@ public static enum ShaderType { | |
private static final String glFragColorKeyword = "gl_FragColor"; | ||
private static final String glFragDataKeyword = "gl_FragData"; | ||
private static final String glFragColorRep = dmEngineGeneratedRep + glFragColorKeyword; | ||
private static final String glFragColorAttrRep = "\nout vec4 " + glFragColorRep + ";\n"; | ||
private static final String glFragColorAttrRep = "\nout vec4 " + glFragColorRep + "%s;\n"; | ||
private static final String floatPrecisionAttrRep = "precision mediump float;\n"; | ||
|
||
public static Result transform(String input, ShaderType shaderType, String targetProfile, int targetVersion, boolean useLatestFeatures) throws CompileExceptionError { | ||
|
@@ -246,12 +247,27 @@ public static Result transform(String input, ShaderType shaderType, String targe | |
input = input.replaceAll("\\b" + keywordRep[0] + "\\b", keywordRep[1]); | ||
} | ||
|
||
// Get data output array size | ||
Matcher fragDataArrayMatcher = regexFragDataArrayPattern.matcher(input); | ||
int maxColorOutputs = 1; | ||
while (fragDataArrayMatcher.find()) { | ||
String fragDataArrayIndex = fragDataArrayMatcher.group("index"); | ||
maxColorOutputs = Math.max(maxColorOutputs, Integer.parseInt(fragDataArrayIndex) + 1); | ||
} | ||
|
||
// Replace fragment output variables | ||
boolean output_glFragColor = input.contains(glFragColorKeyword); | ||
boolean output_glFragData = input.contains(glFragDataKeyword); | ||
|
||
if (output_glFragColor) | ||
input = input.replaceAll("\\b" + glFragColorKeyword + "\\b", glFragColorRep); | ||
{ | ||
input = input.replaceAll("\\b" + glFragColorKeyword + "\\b", glFragColorRep + "_0"); | ||
} | ||
|
||
if (output_glFragData) | ||
input = input.replaceAll("\\b" + glFragDataKeyword + "\\b", glFragColorRep); | ||
{ | ||
input = input.replaceAll("\\b" + glFragDataKeyword + "\\[(\\d+)\\]", glFragColorRep + "_$1"); | ||
} | ||
|
||
Comment on lines
+268
to
271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously the gl_FragData keyword would be replaced with the same color output as gl_FragColor, but that doesn't work for multiple outputs. Instead we generate specific outputs for each assignment of gl_FragData[x] into gl_FragData_x variables. |
||
// Split into slices separated by semicolon, curly bracket scopes and preprocessor definition lines: ";", "{", "}" and "#..<\n>" | ||
// This to reduce parsing complexity | ||
|
@@ -333,8 +349,10 @@ else if (line.contains("precision")) { | |
if(floatPrecisionIndex < 0 && targetProfile.equals("es")) { | ||
output.add(patchLineIndex++, floatPrecisionAttrRep); | ||
} | ||
// insert fragcolor out attr | ||
output.add(patchLineIndex++, glFragColorAttrRep); | ||
for (int i = 0; i < maxColorOutputs; i++) { | ||
// insert fragcolor out attr | ||
output.add(patchLineIndex++, String.format(glFragColorAttrRep, "_" + i)); | ||
} | ||
Comment on lines
+352
to
+355
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There will always be at least one output |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GLSL transformation now supports multiple outputs, so the default will always be postfixed with _0.