automatic glsl 120 to 150 conversion partially working

This commit is contained in:
codeanticode
2013-10-20 20:51:19 -04:00
parent 217b63b5f6
commit 7e1acf5710
3 changed files with 85 additions and 24 deletions
+18 -16
View File
@@ -6387,9 +6387,9 @@ public class PGraphicsOpenGL extends PGraphics {
if (tex) {
if (useDefault || !polyShader.checkPolyType(PShader.TEXLIGHT)) {
if (defTexlightShader == null) {
defTexlightShader = new PShader(parent,
defTexlightShaderVertURL,
defTextureShaderFragURL);
String[] vertSource = pgl.loadVertexShader(defTexlightShaderVertURL);
String[] fragSource = pgl.loadFragmentShader(defTextureShaderFragURL);
defTexlightShader = new PShader(parent, vertSource, fragSource);
}
shader = defTexlightShader;
} else {
@@ -6398,9 +6398,9 @@ public class PGraphicsOpenGL extends PGraphics {
} else {
if (useDefault || !polyShader.checkPolyType(PShader.LIGHT)) {
if (defLightShader == null) {
defLightShader = new PShader(parent,
defLightShaderVertURL,
defColorShaderFragURL);
String[] vertSource = pgl.loadVertexShader(defLightShaderVertURL);
String[] fragSource = pgl.loadFragmentShader(defColorShaderFragURL);
defLightShader = new PShader(parent, vertSource, fragSource);
}
shader = defLightShader;
} else {
@@ -6416,9 +6416,9 @@ public class PGraphicsOpenGL extends PGraphics {
if (tex) {
if (useDefault || !polyShader.checkPolyType(PShader.TEXTURE)) {
if (defTextureShader == null) {
defTextureShader = new PShader(parent,
defTextureShaderVertURL,
defTextureShaderFragURL);
String[] vertSource = pgl.loadVertexShader(defTextureShaderVertURL);
String[] fragSource = pgl.loadFragmentShader(defTextureShaderFragURL);
defTextureShader = new PShader(parent, vertSource, fragSource);
}
shader = defTextureShader;
} else {
@@ -6427,9 +6427,9 @@ public class PGraphicsOpenGL extends PGraphics {
} else {
if (useDefault || !polyShader.checkPolyType(PShader.COLOR)) {
if (defColorShader == null) {
defColorShader = new PShader(parent,
defColorShaderVertURL,
defColorShaderFragURL);
String[] vertSource = pgl.loadVertexShader(defColorShaderVertURL);
String[] fragSource = pgl.loadFragmentShader(defColorShaderFragURL);
defColorShader = new PShader(parent, vertSource, fragSource);
}
shader = defColorShader;
} else {
@@ -6450,8 +6450,9 @@ public class PGraphicsOpenGL extends PGraphics {
PShader shader;
if (lineShader == null) {
if (defLineShader == null) {
defLineShader = new PShader(parent, defLineShaderVertURL,
defLineShaderFragURL);
String[] vertSource = pgl.loadVertexShader(defLineShaderVertURL);
String[] fragSource = pgl.loadFragmentShader(defLineShaderFragURL);
defLineShader = new PShader(parent, vertSource, fragSource);
}
shader = defLineShader;
} else {
@@ -6468,8 +6469,9 @@ public class PGraphicsOpenGL extends PGraphics {
PShader shader;
if (pointShader == null) {
if (defPointShader == null) {
defPointShader = new PShader(parent, defPointShaderVertURL,
defPointShaderFragURL);
String[] vertSource = pgl.loadVertexShader(defPointShaderVertURL);
String[] fragSource = pgl.loadFragmentShader(defPointShaderFragURL);
defPointShader = new PShader(parent, vertSource, fragSource);
}
shader = defPointShader;
} else {
+64 -6
View File
@@ -4,6 +4,8 @@ import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.FontMetrics;
import java.io.IOException;
import java.net.URL;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
@@ -32,6 +34,7 @@ import javax.media.opengl.glu.GLU;
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PGraphics;
import processing.event.KeyEvent;
import processing.event.MouseEvent;
@@ -52,7 +55,7 @@ import javax.media.opengl.glu.GLUtessellatorCallbackAdapter;
public class PJOGL extends PGL {
// OpenGL profile to use (2, 3 or 4)
public static int PROFILE = 2;
public static int PROFILE = 3;
// The two windowing toolkits available to use in JOGL:
public static final int AWT = 0; // http://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing
@@ -822,11 +825,11 @@ public class PJOGL extends PGL {
} catch (javax.media.opengl.GLException e) {
gl3 = null;
}
System.out.println("************");
System.out.println("gl: " + gl);
System.out.println("gl2: " + gl2);
System.out.println("gl2x: " + gl2x);
System.out.println("gl3: " + gl3);
// System.out.println("************");
// System.out.println("gl: " + gl);
// System.out.println("gl2: " + gl2);
// System.out.println("gl2x: " + gl2x);
// System.out.println("gl3: " + gl3);
}
}
@@ -1035,6 +1038,61 @@ public class PJOGL extends PGL {
}
@Override
protected String[] loadFragmentShader(URL url) {
try {
String[] fragSrc0 = PApplet.loadStrings(url.openStream());
// PApplet.join(PApplet.loadStrings(url.openStream()), "\n");
String[] fragSrc = new String[fragSrc0.length + 2];
fragSrc[0] = "#version 150";
fragSrc[1] = "out vec4 fragColor;";
for (int i = 0; i < fragSrc0.length; i++) {
String line = fragSrc0[i];
System.out.print(line + " ---> ");
line = line.replace("varying", "in");
line = line.replace("attribute", "in");
line = line.replace("gl_FragColor", "fragColor");
line = line.replace("texture", "texSampler");
line = line.replace("texSampler2D(", "texture(");
fragSrc[i + 2] = line;
System.out.println(line);
}
return fragSrc;
} catch (IOException e) {
PGraphics.showException("Cannot load fragment shader " + url.getFile());
}
return null;
}
@Override
protected String[] loadVertexShader(URL url) {
try {
String[] vertSrc0 = PApplet.loadStrings(url.openStream());
String[] vertSrc = new String[vertSrc0.length + 1];
vertSrc[0] = "#version 150";
for (int i = 0; i < vertSrc0.length; i++) {
String line = vertSrc0[i];
System.out.print(line + " ---> ");
line = line.replace("attribute", "in");
line = line.replace("varying", "out");
vertSrc[i + 1] = line;
System.out.println(line);
}
return vertSrc;
//PApplet.join(PApplet.loadStrings(url.openStream()), "\n");
} catch (IOException e) {
PGraphics.showException("Cannot load vertex shader " + url.getFile());
}
return null;
}
///////////////////////////////////////////////////////////
// Tessellator
+3 -2
View File
@@ -25,7 +25,6 @@ package processing.opengl;
import processing.core.*;
import java.io.IOException;
import java.net.URL;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
@@ -1090,10 +1089,12 @@ public class PShader implements PConstants {
lightSpotLoc = getUniformLoc("lightSpot");
textureLoc = getUniformLoc("texture");
if (textureLoc == -1) {
textureLoc = getUniformLoc("texSampler");
}
texMatrixLoc = getUniformLoc("texMatrix");
texOffsetLoc = getUniformLoc("texOffset");
perspectiveLoc = getUniformLoc("perspective");
scaleLoc = getUniformLoc("scale");
}