mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 21:59:20 +01:00
Detect GLSL version and preprocess to that
This commit is contained in:
@@ -1668,7 +1668,16 @@ public abstract class PGL {
|
||||
|
||||
protected static String[] preprocessFragmentSource(String[] fragSrc0,
|
||||
int version) {
|
||||
if (version >= 130) {
|
||||
String[] fragSrc;
|
||||
|
||||
if (version < 130) {
|
||||
String[] search = { };
|
||||
String[] replace = { };
|
||||
int offset = 1;
|
||||
|
||||
fragSrc = preprocessShaderSource(fragSrc0, search, replace, offset);
|
||||
fragSrc[0] = "#version " + version;
|
||||
} else {
|
||||
// We need to replace 'texture' uniform by 'texMap' uniform and
|
||||
// 'textureXXX()' functions by 'texture()' functions. Order of these
|
||||
// replacements is important to prevent collisions between these two.
|
||||
@@ -1684,19 +1693,28 @@ public abstract class PGL {
|
||||
"texture", "texture", "texture", "texture",
|
||||
"fragColor"
|
||||
};
|
||||
int offset = 2;
|
||||
|
||||
String[] fragSrc = preprocessShaderSource(fragSrc0, search, replace, 2);
|
||||
fragSrc = preprocessShaderSource(fragSrc0, search, replace, offset);
|
||||
fragSrc[0] = "#version " + version;
|
||||
fragSrc[1] = "out vec4 fragColor;";
|
||||
|
||||
return fragSrc;
|
||||
}
|
||||
return fragSrc0;
|
||||
|
||||
return fragSrc;
|
||||
}
|
||||
|
||||
protected static String[] preprocessVertexSource(String[] vertSrc0,
|
||||
int version) {
|
||||
if (version >= 130) {
|
||||
String[] vertSrc;
|
||||
|
||||
if (version < 130) {
|
||||
String[] search = { };
|
||||
String[] replace = { };
|
||||
int offset = 1;
|
||||
|
||||
vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
|
||||
vertSrc[0] = "#version " + version;
|
||||
} else {
|
||||
// We need to replace 'texture' uniform by 'texMap' uniform and
|
||||
// 'textureXXX()' functions by 'texture()' functions. Order of these
|
||||
// replacements is important to prevent collisions between these two.
|
||||
@@ -1710,13 +1728,13 @@ public abstract class PGL {
|
||||
"texMap",
|
||||
"texture", "texture", "texture", "texture"
|
||||
};
|
||||
int offset = 1;
|
||||
|
||||
String[] vertSrc = preprocessShaderSource(vertSrc0, search, replace, 1);
|
||||
vertSrc = preprocessShaderSource(vertSrc0, search, replace, offset);
|
||||
vertSrc[0] = "#version " + version;
|
||||
|
||||
return vertSrc;
|
||||
}
|
||||
return vertSrc0;
|
||||
|
||||
return vertSrc;
|
||||
}
|
||||
|
||||
protected static String[] preprocessShaderSource(String[] src0,
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import com.jogamp.common.util.VersionNumber;
|
||||
import com.jogamp.opengl.GL;
|
||||
import com.jogamp.opengl.GL2;
|
||||
import com.jogamp.opengl.GL2ES1;
|
||||
@@ -1238,37 +1239,30 @@ public class PJOGL extends PGL {
|
||||
}
|
||||
|
||||
|
||||
private static int getGLSLVersion(GLContext context) {
|
||||
VersionNumber vn = context.getGLSLVersionNumber();
|
||||
return vn.getMajor() * 100 + vn.getMinor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] loadVertexShader(String filename, int version) {
|
||||
if (PApplet.platform == PConstants.MACOSX) {
|
||||
String[] fragSrc0 = pg.parent.loadStrings(filename);
|
||||
return preprocessFragmentSource(fragSrc0, 130);
|
||||
} else {
|
||||
return pg.parent.loadStrings(filename);
|
||||
}
|
||||
String[] fragSrc0 = pg.parent.loadStrings(filename);
|
||||
return preprocessFragmentSource(fragSrc0, getGLSLVersion(context));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] loadFragmentShader(String filename, int version) {
|
||||
if (PApplet.platform == PConstants.MACOSX) {
|
||||
String[] vertSrc0 = pg.parent.loadStrings(filename);
|
||||
return preprocessVertexSource(vertSrc0, 130);
|
||||
} else {
|
||||
return pg.parent.loadStrings(filename);
|
||||
}
|
||||
String[] vertSrc0 = pg.parent.loadStrings(filename);
|
||||
return preprocessVertexSource(vertSrc0, getGLSLVersion(context));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String[] loadFragmentShader(URL url, int version) {
|
||||
try {
|
||||
if (PApplet.platform == PConstants.MACOSX) {
|
||||
String[] fragSrc0 = PApplet.loadStrings(url.openStream());
|
||||
return preprocessFragmentSource(fragSrc0, 130);
|
||||
} else {
|
||||
return PApplet.loadStrings(url.openStream());
|
||||
}
|
||||
String[] fragSrc0 = PApplet.loadStrings(url.openStream());
|
||||
return preprocessFragmentSource(fragSrc0, getGLSLVersion(context));
|
||||
} catch (IOException e) {
|
||||
PGraphics.showException("Cannot load fragment shader " + url.getFile());
|
||||
}
|
||||
@@ -1279,12 +1273,8 @@ public class PJOGL extends PGL {
|
||||
@Override
|
||||
protected String[] loadVertexShader(URL url, int version) {
|
||||
try {
|
||||
if (PApplet.platform == PConstants.MACOSX) {
|
||||
String[] vertSrc0 = PApplet.loadStrings(url.openStream());
|
||||
return preprocessVertexSource(vertSrc0, 130);
|
||||
} else {
|
||||
return PApplet.loadStrings(url.openStream());
|
||||
}
|
||||
String[] vertSrc0 = PApplet.loadStrings(url.openStream());
|
||||
return preprocessVertexSource(vertSrc0, getGLSLVersion(context));
|
||||
} catch (IOException e) {
|
||||
PGraphics.showException("Cannot load vertex shader " + url.getFile());
|
||||
}
|
||||
|
||||
@@ -195,11 +195,7 @@ public class PSurfaceJOGL implements PSurface {
|
||||
if (profile == null) {
|
||||
if (PJOGL.profile == 2) {
|
||||
try {
|
||||
if (PApplet.platform == PConstants.MACOSX) {
|
||||
profile = GLProfile.getMaxProgrammableCore(true);
|
||||
} else {
|
||||
profile = GLProfile.getGL2ES2();
|
||||
}
|
||||
profile = GLProfile.getGL2ES2();
|
||||
} catch (GLException ex) {
|
||||
profile = GLProfile.getMaxProgrammable(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user