From a56c5effef7a8ed1a11cca9d8bcd554cdebf7431 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sun, 20 Oct 2013 18:11:49 -0400 Subject: [PATCH] added GLSL 150 versions of the texture drawing shaders --- core/src/processing/opengl/PGL.java | 69 +++++++++++++++++++-------- core/src/processing/opengl/PJOGL.java | 15 ++++-- 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 4f91aa09b..a1135d789 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -183,30 +183,59 @@ public abstract class PGL { "precision mediump int;\n" + "#endif\n"; - protected static String texVertShaderSource = - "attribute vec2 inVertex;" + - "attribute vec2 inTexcoord;" + - "varying vec2 vertTexcoord;" + - "void main() {" + - " gl_Position = vec4(inVertex, 0, 1);" + - " vertTexcoord = inTexcoord;" + - "}"; + protected static String[] texVertShaderSource = { + "attribute vec2 inVertex;\n" + + "attribute vec2 inTexcoord;\n" + + "varying vec2 vertTexcoord;\n" + + "void main() {\n" + + " gl_Position = vec4(inVertex, 0, 1);\n" + + " vertTexcoord = inTexcoord;\n" + + "}\n", + "#version 150\n" + + "in vec2 inVertex;\n" + + "in vec2 inTexcoord;\n" + + "out vec2 vertTexcoord;" + + "void main() {\n" + + " gl_Position = vec4(inVertex, 0, 1);\n" + + " vertTexcoord = inTexcoord;\n" + + "}\n" + }; - protected static String tex2DFragShaderSource = + protected static String[] tex2DFragShaderSource = { SHADER_PREPROCESSOR_DIRECTIVE + - "uniform sampler2D textureSampler;" + - "varying vec2 vertTexcoord;" + - "void main() {" + - " gl_FragColor = texture2D(textureSampler, vertTexcoord.st);" + - "}"; + "uniform sampler2D textureSampler;\n" + + "varying vec2 vertTexcoord;\n" + + "void main() {\n" + + " gl_FragColor = texture2D(textureSampler, vertTexcoord.st);\n" + + "}\n", + "#version 150\n" + + SHADER_PREPROCESSOR_DIRECTIVE + + "uniform sampler2D textureSampler;\n" + + "in vec2 vertTexcoord;\n" + + "out vec4 fragColor;\n" + + "void main() {\n" + + " fragColor = texture(textureSampler, vertTexcoord.st);\n" + + "}\n" + }; - protected static String texRectFragShaderSource = + protected static String[] texRectFragShaderSource = { SHADER_PREPROCESSOR_DIRECTIVE + "uniform sampler2DRect textureSampler;" + "varying vec2 vertTexcoord;" + "void main() {" + " gl_FragColor = texture2DRect(textureSampler, vertTexcoord.st);" + - "}"; + "}", + "#version 150\n" + + SHADER_PREPROCESSOR_DIRECTIVE + + "uniform sampler2DRect textureSampler;\n" + + "in vec2 vertTexcoord;\n" + + "out vec4 fragColor;\n" + + "void main() {\n" + + " fragColor = texture(textureSampler, vertTexcoord.st);\n" + + "}\n" + }; + + protected static int shaderSource = 0; /** Which texturing targets are enabled */ protected static boolean[] texturingTargets = { false, false }; @@ -887,8 +916,8 @@ public abstract class PGL { int texX0, int texY0, int texX1, int texY1, int scrX0, int scrY0, int scrX1, int scrY1) { if (!loadedTex2DShader || tex2DShaderContext != glContext) { - tex2DVertShader = createShader(VERTEX_SHADER, texVertShaderSource); - tex2DFragShader = createShader(FRAGMENT_SHADER, tex2DFragShaderSource); + tex2DVertShader = createShader(VERTEX_SHADER, texVertShaderSource[shaderSource]); + tex2DFragShader = createShader(FRAGMENT_SHADER, tex2DFragShaderSource[shaderSource]); if (0 < tex2DVertShader && 0 < tex2DFragShader) { tex2DShaderProgram = createProgram(tex2DVertShader, tex2DFragShader); } @@ -998,8 +1027,8 @@ public abstract class PGL { int texX0, int texY0, int texX1, int texY1, int scrX0, int scrY0, int scrX1, int scrY1) { if (!loadedTexRectShader || texRectShaderContext != glContext) { - texRectVertShader = createShader(VERTEX_SHADER, texVertShaderSource); - texRectFragShader = createShader(FRAGMENT_SHADER, texRectFragShaderSource); + texRectVertShader = createShader(VERTEX_SHADER, texVertShaderSource[shaderSource]); + texRectFragShader = createShader(FRAGMENT_SHADER, texRectFragShaderSource[shaderSource]); if (0 < texRectVertShader && 0 < texRectFragShader) { texRectShaderProgram = createProgram(texRectVertShader, texRectFragShader); diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index 654e98d62..607651709 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -53,7 +53,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 @@ -231,10 +231,15 @@ public class PJOGL extends PGL { @Override protected void initSurface(int antialias) { if (profile == null) { - if (PROFILE == 2) profile = GLProfile.getGL2ES1(); - else if (PROFILE == 3) profile = GLProfile.getGL2GL3(); - else if (PROFILE == 4) profile = GLProfile.getGL4ES3(); - else throw new RuntimeException("Unsupported profile."); + if (PROFILE == 2) { + profile = GLProfile.getGL2ES1(); + } else if (PROFILE == 3) { + profile = GLProfile.getGL2GL3(); + shaderSource = 1; + } else if (PROFILE == 4) { + profile = GLProfile.getGL4ES3(); + shaderSource = 1; + } else throw new RuntimeException("Unsupported profile."); System.out.println(profile); } else { // Restarting...