Explorar el Código

GL ES 3.0 megapatch (#2061)

* Extend GL ES 3.0 support. Enable CoreProfile capability when using GL ES 3.0. Add WebGL caps.

* Fix contrast adjustment matdef

* Improve GL ->GLES compatibility: Detect if RGB float attachment is supported, implement correct glDrawBuffer shim, add explicit GLES 300 support in all materials

* Allow setReadDrawBuffers in GLES 30+, add DepthTexture capability in GLES 30+

* Make passing boundDrawBufferId to shaders toggleable (default true). Disable in tests

* Revert "Allow setReadDrawBuffers in GLES 30+, add DepthTexture capability in GLES 30+"

This reverts commit d8c7e96d2937bcaa68527cb1b8171a2e11124d35.

* Fix tests

* Set default precision in GLSLCompat only if supported

* Set highp for samplerCube and int. Do not check for GL_FRAGMENT_PRECISION_HIGH as it is not always declared despite the specs.

* Fix GLES formats declaration
Riccardo Balbo hace 2 años
padre
commit
4e851bfeeb
Se han modificado 75 ficheros con 568 adiciones y 343 borrados
  1. 28 4
      jme3-android/src/main/java/com/jme3/renderer/android/AndroidGL.java
  2. 5 3
      jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java
  3. 4 2
      jme3-core/src/main/java/com/jme3/post/HDRRenderer.java
  4. 16 0
      jme3-core/src/main/java/com/jme3/renderer/Caps.java
  5. 39 1
      jme3-core/src/main/java/com/jme3/renderer/RenderManager.java
  6. 6 0
      jme3-core/src/main/java/com/jme3/renderer/Renderer.java
  7. 7 0
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLES_30.java
  8. 1 1
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java
  9. 48 42
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
  10. 5 0
      jme3-core/src/main/java/com/jme3/system/NullRenderer.java
  11. 12 2
      jme3-core/src/main/java/com/jme3/system/Platform.java
  12. 7 2
      jme3-core/src/main/resources/Common/MatDefs/Blur/HGaussianBlur.j3md
  13. 4 2
      jme3-core/src/main/resources/Common/MatDefs/Blur/RadialBlur.j3md
  14. 7 2
      jme3-core/src/main/resources/Common/MatDefs/Blur/VGaussianBlur.j3md
  15. 4 15
      jme3-core/src/main/resources/Common/MatDefs/Gui/Gui.j3md
  16. 4 2
      jme3-core/src/main/resources/Common/MatDefs/Hdr/LogLum.j3md
  17. 4 2
      jme3-core/src/main/resources/Common/MatDefs/Hdr/ToneMap.j3md
  18. 4 2
      jme3-core/src/main/resources/Common/MatDefs/Light/Deferred.j3md
  19. 2 0
      jme3-core/src/main/resources/Common/MatDefs/Light/Deferred.vert
  20. 2 0
      jme3-core/src/main/resources/Common/MatDefs/Light/GBuf.vert
  21. 20 13
      jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md
  22. 17 11
      jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md
  23. 7 5
      jme3-core/src/main/resources/Common/MatDefs/Misc/ColoredTextured.j3md
  24. 2 0
      jme3-core/src/main/resources/Common/MatDefs/Misc/ColoredTextured.vert
  25. 13 8
      jme3-core/src/main/resources/Common/MatDefs/Misc/Particle.j3md
  26. 4 2
      jme3-core/src/main/resources/Common/MatDefs/Misc/ShowNormals.j3md
  27. 4 2
      jme3-core/src/main/resources/Common/MatDefs/Misc/Sky.j3md
  28. 4 2
      jme3-core/src/main/resources/Common/MatDefs/Misc/SkyNonCube.j3md
  29. 16 10
      jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md
  30. 4 2
      jme3-core/src/main/resources/Common/MatDefs/Shadow/BasicPostShadow.j3md
  31. 4 2
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow.j3md
  32. 7 4
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.j3md
  33. 10 2
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PreShadow.j3md
  34. 32 4
      jme3-core/src/main/resources/Common/ShaderLib/GLSLCompat.glsllib
  35. 1 1
      jme3-core/src/test/java/com/jme3/material/MaterialMatParamTest.java
  36. 1 1
      jme3-core/src/test/java/com/jme3/material/MaterialTest.java
  37. 10 2
      jme3-core/src/test/java/com/jme3/system/TestUtil.java
  38. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/BloomExtract.j3md
  39. 5 3
      jme3-effects/src/main/resources/Common/MatDefs/Post/BloomFinal.j3md
  40. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/CartoonEdge.j3md
  41. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/Compose.j3md
  42. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/ContrastAdjustment.frag
  43. 10 6
      jme3-effects/src/main/resources/Common/MatDefs/Post/ContrastAdjustment.j3md
  44. 0 95
      jme3-effects/src/main/resources/Common/MatDefs/Post/ContrastAdjustment15.frag
  45. 7 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/CrossHatch.j3md
  46. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/DepthOfField.j3md
  47. 7 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/FXAA.j3md
  48. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/Fade.j3md
  49. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/Fog.j3md
  50. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/LightScattering.j3md
  51. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/Overlay.j3md
  52. 2 0
      jme3-effects/src/main/resources/Common/MatDefs/Post/Post15.vert
  53. 5 3
      jme3-effects/src/main/resources/Common/MatDefs/Post/Posterization.j3md
  54. 4 2
      jme3-effects/src/main/resources/Common/MatDefs/Post/ToneMap.j3md
  55. 3 1
      jme3-effects/src/main/resources/Common/MatDefs/SSAO/ssao.j3md
  56. 3 1
      jme3-effects/src/main/resources/Common/MatDefs/SSAO/ssaoBlur.j3md
  57. 7 2
      jme3-effects/src/main/resources/Common/MatDefs/Water/SimpleWater.j3md
  58. 3 1
      jme3-effects/src/main/resources/Common/MatDefs/Water/Water.j3md
  59. 15 0
      jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java
  60. 2 2
      jme3-niftygui/src/main/resources/Common/MatDefs/Nifty/NiftyQuad.j3md
  61. 2 2
      jme3-niftygui/src/main/resources/Common/MatDefs/Nifty/NiftyQuadGrad.j3md
  62. 2 2
      jme3-niftygui/src/main/resources/Common/MatDefs/Nifty/NiftyTex.j3md
  63. 10 6
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md
  64. 7 2
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/HeightBasedTerrain.j3md
  65. 10 6
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md
  66. 4 2
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Terrain.j3md
  67. 16 10
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md
  68. 2 0
      jme3-testdata/src/main/resources/Materials/Geom/SimpleGeom.geom
  69. 2 0
      jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tsctrl
  70. 2 0
      jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval
  71. 7 4
      jme3-vr/src/main/resources/Common/MatDefs/VR/CartoonSSAO.j3md
  72. 7 4
      jme3-vr/src/main/resources/Common/MatDefs/VR/GuiOverlay.j3md
  73. 9 6
      jme3-vr/src/main/resources/Common/MatDefs/VR/OpenVR.j3md
  74. 7 4
      jme3-vr/src/main/resources/Common/MatDefs/VR/PostShadowFilter.j3md
  75. 7 4
      jme3-vr/src/main/resources/Common/MatDefs/VR/Unshaded.j3md

+ 28 - 4
jme3-android/src/main/java/com/jme3/renderer/android/AndroidGL.java

@@ -45,6 +45,7 @@ import java.nio.ShortBuffer;
 public class AndroidGL implements GL, GL2, GLES_30, GLExt, GLFbo {
 
     IntBuffer tmpBuff = BufferUtils.createIntBuffer(1);
+    IntBuffer tmpBuff16 = BufferUtils.createIntBuffer(16);
 
     @Override
     public void resetStats() {
@@ -694,10 +695,17 @@ public class AndroidGL implements GL, GL2, GLES_30, GLExt, GLFbo {
     // Wrapper to DrawBuffers as there's no DrawBuffer method in GLES
     @Override
     public void glDrawBuffer(int mode) {
-        tmpBuff.clear();
-        tmpBuff.put(0, mode);
-        tmpBuff.rewind();
-        glDrawBuffers(tmpBuff);
+        int nBuffers = (mode - GLFbo.GL_COLOR_ATTACHMENT0_EXT) + 1;
+        if (nBuffers <= 0 || nBuffers > 16) {
+            throw new IllegalArgumentException("Draw buffer outside range: " + Integer.toHexString(mode));
+        }
+        tmpBuff16.clear();
+        for (int i = 0; i < nBuffers - 1; i++) {
+            tmpBuff16.put(GL.GL_NONE);
+        }
+        tmpBuff16.put(mode);
+        tmpBuff16.flip();
+        glDrawBuffers(tmpBuff16);
     }
 
     @Override
@@ -729,5 +737,21 @@ public class AndroidGL implements GL, GL2, GLES_30, GLExt, GLFbo {
         GLES30.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
     }
 
+    @Override
+    public void glBindVertexArray(int array) {
+        GLES30.glBindVertexArray(array);
+    }
+
+    @Override
+    public void glDeleteVertexArrays(IntBuffer arrays) {
+       GLES30.glDeleteVertexArrays(arrays.limit(),arrays);
+    }
+
+    @Override
+    public void glGenVertexArrays(IntBuffer arrays) {
+        GLES30.glGenVertexArrays(arrays.limit(),arrays);
+
+    }
+
 }
 

+ 5 - 3
jme3-core/src/main/java/com/jme3/post/FilterPostProcessor.java

@@ -149,10 +149,12 @@ public class FilterPostProcessor implements SceneProcessor, Savable {
         fsQuad.setHeight(1);
 
         if (!renderer.getCaps().contains(Caps.PackedFloatTexture)) {
-            if (!renderer.getCaps().contains(Caps.FloatTexture)) {
-                fbFormat = Format.RGB8;
-            } else {
+            if(renderer.getCaps().contains(Caps.FloatColorBufferRGB)){
                 fbFormat = Format.RGB16F;
+            } else if(renderer.getCaps().contains(Caps.FloatColorBufferRGBA)){
+                fbFormat = Format.RGBA16F;
+            } else {
+                fbFormat = Format.RGB8;
             }
         }
 

+ 4 - 2
jme3-core/src/main/java/com/jme3/post/HDRRenderer.java

@@ -91,7 +91,7 @@ public class HDRRenderer implements SceneProcessor {
     private float whiteLevel = 100f;
     private float throttle = -1;
     private int maxIterations = -1;
-    private Image.Format bufFormat = Format.RGB16F;
+    private Image.Format bufFormat = Format.RGB8;
 
     private MinFilter fbMinFilter = MinFilter.BilinearNoMipMaps;
     private MagFilter fbMagFilter = MagFilter.Bilinear;
@@ -106,8 +106,10 @@ public class HDRRenderer implements SceneProcessor {
         Collection<Caps> caps = renderer.getCaps();
         if (caps.contains(Caps.PackedFloatColorBuffer))
             bufFormat = Format.RGB111110F;
-        else if (caps.contains(Caps.FloatColorBuffer))
+        else if (caps.contains(Caps.FloatColorBufferRGB))
             bufFormat = Format.RGB16F;
+        else if (caps.contains(Caps.FloatColorBufferRGBA))
+            bufFormat = Format.RGBA16F;
         else {
             enabled = false;
             return;

+ 16 - 0
jme3-core/src/main/java/com/jme3/renderer/Caps.java

@@ -227,6 +227,16 @@ public enum Caps {
      */
     FloatTexture,
 
+    /**
+     * Supports rendering on RGB floating point textures
+     */
+    FloatColorBufferRGB,
+
+    /**
+     * Supports rendering on RGBA floating point textures
+     */
+    FloatColorBufferRGBA,
+
     /**
      * Supports integer textures.
      */
@@ -236,6 +246,7 @@ public enum Caps {
      * Supports floating point FBO color buffers (Format.RGB16F).
      */
     FloatColorBuffer,
+    
 
     /**
      * Supports floating point depth buffer.
@@ -341,6 +352,11 @@ public enum Caps {
      */
     OpenGLES20,
 
+    /**
+     * Supports WebGL
+     */
+    WebGL,
+
     /**
      * Supports RGB8 / RGBA8 textures.
      */

+ 39 - 1
jme3-core/src/main/java/com/jme3/renderer/RenderManager.java

@@ -58,8 +58,10 @@ import com.jme3.scene.VertexBuffer;
 import com.jme3.shader.Shader;
 import com.jme3.shader.UniformBinding;
 import com.jme3.shader.UniformBindingManager;
+import com.jme3.shader.VarType;
 import com.jme3.system.NullRenderer;
 import com.jme3.system.Timer;
+import com.jme3.texture.FrameBuffer;
 import com.jme3.util.SafeArrayList;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -101,6 +103,7 @@ public class RenderManager {
     private LightFilter lightFilter = new DefaultLightFilter();
     private TechniqueDef.LightMode preferredLightMode = TechniqueDef.LightMode.MultiPass;
     private int singlePassLightBatchSize = 1;
+    private MatParamOverride boundDrawBufferId=new MatParamOverride(VarType.Int,"BoundDrawBuffer",0);
 
 
     /**
@@ -111,6 +114,7 @@ public class RenderManager {
      */
     public RenderManager(Renderer renderer) {
         this.renderer = renderer;
+        this.forcedOverrides.add(boundDrawBufferId);
     }
 
     /**
@@ -629,6 +633,12 @@ public class RenderManager {
             setWorldMatrix(geom.getWorldMatrix());
         }
 
+        // Use material override to pass the current target index (used in api such as GL ES that do not support glDrawBuffer)
+        FrameBuffer currentFb = this.renderer.getCurrentFrameBuffer();
+        if (currentFb != null && !currentFb.isMultiTarget()) {
+            this.boundDrawBufferId.setValue(currentFb.getTargetIndex());
+        }
+
         // Perform light filtering if we have a light filter.
         LightList lightList = geom.getWorldLightList();
 
@@ -639,7 +649,7 @@ public class RenderManager {
         }
 
         Material material = geom.getMaterial();
-
+        
         // If forcedTechnique exists, we try to force it for the render.
         // If it does not exist in the mat def, we check for forcedMaterial and render the geom if not null.
         // Otherwise, the geometry is not rendered.
@@ -1298,4 +1308,32 @@ public class RenderManager {
             }
         }
     }
+
+
+    /**
+     * Returns true if the draw buffer target id is passed to the shader.
+     * 
+     * @return True if the draw buffer target id is passed to the shaders.
+     */
+    public boolean getPassDrawBufferTargetIdToShaders() {
+        return this.forcedOverrides.contains(boundDrawBufferId);
+    }
+
+    /**
+     * Enable or disable passing the draw buffer target id to the shaders. This
+     * is needed to handle FrameBuffer.setTargetIndex correctly in some
+     * backends.
+     * 
+     * @param v
+     *            True to enable, false to disable (default is true)
+     */
+    public void setPassDrawBufferTargetIdToShaders(boolean v) {
+        if (v) {
+            if (!this.forcedOverrides.contains(boundDrawBufferId)) {
+                this.forcedOverrides.add(boundDrawBufferId);
+            }
+        } else {
+            this.forcedOverrides.remove(boundDrawBufferId);
+        }
+    }
 }

+ 6 - 0
jme3-core/src/main/java/com/jme3/renderer/Renderer.java

@@ -527,4 +527,10 @@ public interface Renderer {
  
     }
     
+    /**
+     * Returns the current FrameBuffer that is being rendered to.
+     * @return the FrameBuffer or null if rendering to the screen.
+     */
+    public FrameBuffer getCurrentFrameBuffer();
+
 }

+ 7 - 0
jme3-core/src/main/java/com/jme3/renderer/opengl/GLES_30.java

@@ -31,6 +31,8 @@
  */
 package com.jme3.renderer.opengl;
 
+import java.nio.IntBuffer;
+
 /**
  * GL functions and constants only available on vanilla OpenGL ES 3.0.
  *
@@ -40,5 +42,10 @@ public interface GLES_30 extends GL {
 
     public static final int GL_RGB10_A2 = 0x8059;
     public static final int GL_UNSIGNED_INT_2_10_10_10_REV = 0x8368;
+ 
+    public void glBindVertexArray(int array);
 
+    public void glDeleteVertexArrays(IntBuffer arrays);
+   
+    public void glGenVertexArrays(IntBuffer arrays);
 }

+ 1 - 1
jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java

@@ -121,7 +121,7 @@ public final class GLImageFormats {
             formatSrgbSwiz(formatToGL, Format.Luminance8Alpha8,     GLExt.GL_SRGB8_ALPHA8_EXT, GL3.GL_RG,       GL.GL_UNSIGNED_BYTE);
         }
         
-        if (caps.contains(Caps.OpenGL20)) {
+        if (caps.contains(Caps.OpenGL20)||caps.contains(Caps.OpenGLES30)) {
             if (!caps.contains(Caps.CoreProfile)) {
                 format(formatToGL, Format.Alpha8,           GL2.GL_ALPHA8,            GL.GL_ALPHA,           GL.GL_UNSIGNED_BYTE);
                 format(formatToGL, Format.Luminance8,       GL2.GL_LUMINANCE8,        GL.GL_LUMINANCE,       GL.GL_UNSIGNED_BYTE);

+ 48 - 42
jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java

@@ -187,7 +187,12 @@ public final class GLRenderer implements Renderer {
         return extensionSet;
     }
 
+    public static boolean isWebGL(String version) {
+        return version.contains("WebGL");
+    }
+
     public static int extractVersion(String version) {
+        if (version.startsWith("WebGL 2.0")) return 300;
         Matcher m = GLVERSION_PATTERN.matcher(version);
         if (m.matches()) {
             int major = Integer.parseInt(m.group(1));
@@ -208,7 +213,11 @@ public final class GLRenderer implements Renderer {
     }
 
     private void loadCapabilitiesES() {
-        int oglVer = extractVersion(gl.glGetString(GL.GL_VERSION));
+        String version = gl.glGetString(GL.GL_VERSION);
+        int oglVer = extractVersion(version);
+        if (isWebGL(version)) {
+            caps.add(Caps.WebGL);       
+        }
         caps.add(Caps.GLSL100);
         caps.add(Caps.OpenGLES20);
 
@@ -378,7 +387,7 @@ public final class GLRenderer implements Renderer {
                     hasExtension("GL_ARB_half_float_pixel");
 
             if (!hasFloatTexture) {
-                hasFloatTexture = caps.contains(Caps.OpenGL30);
+                hasFloatTexture = caps.contains(Caps.OpenGL30) || caps.contains(Caps.OpenGLES30);
             }
         }
 
@@ -409,9 +418,14 @@ public final class GLRenderer implements Renderer {
         }
 
         if (hasExtension("GL_ARB_color_buffer_float") &&
-                hasExtension("GL_ARB_half_float_pixel")) {
+                hasExtension("GL_ARB_half_float_pixel")
+                ||caps.contains(Caps.OpenGL30) || caps.contains(Caps.OpenGLES30)) {
             // XXX: Require both 16- and 32-bit float support for FloatColorBuffer.
             caps.add(Caps.FloatColorBuffer);
+            caps.add(Caps.FloatColorBufferRGBA);
+            if (!caps.contains(Caps.OpenGLES30)) {
+                caps.add(Caps.FloatColorBufferRGB);
+            }
         }
 
         if (caps.contains(Caps.OpenGLES30) || hasExtension("GL_ARB_depth_buffer_float")) {
@@ -450,13 +464,13 @@ public final class GLRenderer implements Renderer {
 
         // == end texture format extensions ==
 
-        if (hasExtension("GL_ARB_vertex_array_object") || caps.contains(Caps.OpenGL30)) {
+        if (hasExtension("GL_ARB_vertex_array_object") || caps.contains(Caps.OpenGL30) || caps.contains(Caps.OpenGLES30) ) {
             caps.add(Caps.VertexBufferArray);
         }
 
         if (hasExtension("GL_ARB_texture_non_power_of_two") ||
                 hasExtension("GL_OES_texture_npot") ||
-                caps.contains(Caps.OpenGL30)) {
+                caps.contains(Caps.OpenGL30) || caps.contains(Caps.OpenGLES30)) {
             caps.add(Caps.NonPowerOfTwoTextures);
         } else {
             logger.log(Level.WARNING, "Your graphics card does not "
@@ -530,7 +544,7 @@ public final class GLRenderer implements Renderer {
 
         // Supports sRGB pipeline.
         if ( (hasExtension("GL_ARB_framebuffer_sRGB") && hasExtension("GL_EXT_texture_sRGB"))
-                || caps.contains(Caps.OpenGL30)) {
+                || caps.contains(Caps.OpenGL30) || caps.contains(Caps.OpenGLES30)) {
             caps.add(Caps.Srgb);
         }
 
@@ -539,8 +553,10 @@ public final class GLRenderer implements Renderer {
             caps.add(Caps.SeamlessCubemap);
         }
 
-        if (caps.contains(Caps.OpenGL32) && !hasExtension("GL_ARB_compatibility")) {
-            caps.add(Caps.CoreProfile);
+        if ((caps.contains(Caps.OpenGLES30) || caps.contains(Caps.OpenGL32)) && !hasExtension("GL_ARB_compatibility")) {
+            if (JmeSystem.getPlatform().getOs() != Platform.Os.iOS) { // some features are not supported on iOS
+                caps.add(Caps.CoreProfile);
+            }
         }
 
         if (hasExtension("GL_ARB_get_program_binary")) {
@@ -679,9 +695,17 @@ public final class GLRenderer implements Renderer {
 
         if (caps.contains(Caps.CoreProfile)) {
             // Core Profile requires VAO to be bound.
-            gl3.glGenVertexArrays(intBuf16);
-            int vaoId = intBuf16.get(0);
-            gl3.glBindVertexArray(vaoId);
+            if(gl3!=null){
+                gl3.glGenVertexArrays(intBuf16);
+                int vaoId = intBuf16.get(0);
+                gl3.glBindVertexArray(vaoId);
+            }else if(gl instanceof GLES_30){
+                ((GLES_30)gl).glGenVertexArrays(intBuf16);
+                int vaoId = intBuf16.get(0);
+                ((GLES_30)gl).glBindVertexArray(vaoId);                
+            }   else{
+                throw new UnsupportedOperationException("Core profile not supported");
+            }
         }
         if (gl2 != null && !(gl instanceof GLES_30)) {
             gl2.glEnable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE);
@@ -1521,7 +1545,6 @@ public final class GLRenderer implements Renderer {
                     + "Only GLSL 1.00 shaders are supported.");
         }
 
-        boolean insertPrecision = false;
         // Upload shader source.
         // Merge the defines and source code.
         stringBuf.setLength(0);
@@ -1552,16 +1575,8 @@ public final class GLRenderer implements Renderer {
                 }
             }
 
-            if (gles2 || gles3) {
-                //Inserting precision only to fragment shaders creates some link failures because of different precision between shaders
-                //But adding the precision to all shaders generates rendering glitches in some devices if not set to highp
-                if (source.getType() == ShaderType.Fragment) {
-                    // GLES requires precision qualifier.
-                    insertPrecision = true;
-                }
-            }
         }
-
+        
         if (linearizeSrgbImages) {
             stringBuf.append("#define SRGB 1\n");
         }
@@ -1570,24 +1585,6 @@ public final class GLRenderer implements Renderer {
         stringBuf.append(source.getDefines());
         stringBuf.append(source.getSource());
 
-        if(insertPrecision){
-            // default precision could be defined in GLSLCompat.glsllib so final users can use custom defined precision instead
-            // precision token is not a preprocessor directive therefore it must be placed after #extension tokens to avoid
-            // Error P0001: Extension directive must occur before any non-preprocessor tokens
-            int idx = stringBuf.lastIndexOf("#extension");
-            idx = stringBuf.indexOf("\n", idx);
-
-            if(version>=310) {
-                stringBuf.insert(idx + 1, "precision highp sampler2DMS;\n");
-            }
-            if(version>=300) {
-                stringBuf.insert(idx + 1, "precision highp sampler2DArray;\n");
-                stringBuf.insert(idx + 1, "precision highp sampler2DShadow;\n");
-                stringBuf.insert(idx + 1, "precision highp sampler3D;\n");
-                stringBuf.insert(idx + 1, "precision highp sampler2D;\n");
-            }
-            stringBuf.insert(idx + 1, "precision highp float;\n");
-        }
 
         intBuf1.clear();
         intBuf1.put(0, stringBuf.length());
@@ -1712,7 +1709,7 @@ public final class GLRenderer implements Renderer {
     public void setShader(Shader shader) {
         if (shader == null) {
             throw new IllegalArgumentException("Shader cannot be null");
-        } else {
+        } else {            
             if (shader.isUpdateNeeded()) {
                 updateShaderData(shader);
             }
@@ -2073,8 +2070,17 @@ public final class GLRenderer implements Renderer {
         mainFbOverride = fb;
     }
 
+
+    @Override
+    public FrameBuffer getCurrentFrameBuffer() {
+        if(mainFbOverride!=null){
+            return mainFbOverride;
+        }
+        return context.boundFB;
+    }
+
     public void setReadDrawBuffers(FrameBuffer fb) {
-        if (gl2 == null || gl instanceof GLES_30) {
+        if (gl2 == null) {
             return;
         }
 
@@ -2679,7 +2685,7 @@ public final class GLRenderer implements Renderer {
         if (unit < 0 || unit >= RenderContext.maxTextureUnits) {
             throw new TextureUnitException();
         }
-
+        
         Image image = tex.getImage();
         if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) {
             // Check NPOT requirements

+ 5 - 0
jme3-core/src/main/java/com/jme3/system/NullRenderer.java

@@ -293,4 +293,9 @@ public class NullRenderer implements Renderer {
     public boolean isMainFrameBufferSrgb() {
         return false;
     }
+
+    @Override
+    public FrameBuffer getCurrentFrameBuffer() {
+        return null;
+    }
 }

+ 12 - 2
jme3-core/src/main/java/com/jme3/system/Platform.java

@@ -139,7 +139,13 @@ public enum Platform {
     /**
      * Android running on unknown platform (could be x86 or mips for example).
      */
-    Android_Other(Os.Android);
+    Android_Other(Os.Android),
+    
+    /**
+    * Generic web platform on unknown architecture
+    */
+    Web(Os.Web, true) // assume always 64-bit, it shouldn't matter for web
+    ;
 
     
     /**
@@ -165,7 +171,11 @@ public enum Platform {
         /**
          * Android operating systems
          */
-        Android
+        Android,
+        /**
+         * Generic web platform
+         */
+        Web
     }
 
     private final boolean is64bit;

+ 7 - 2
jme3-core/src/main/resources/Common/MatDefs/Blur/HGaussianBlur.j3md

@@ -1,6 +1,7 @@
 MaterialDef HGaussianBlur {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Texture2D Texture
         Float Size
@@ -8,10 +9,14 @@ MaterialDef HGaussianBlur {
     }
 
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Blur/HGaussianBlur.frag
+        VertexShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Blur/HGaussianBlur.frag
 
         WorldParameters {
         }
+        
+        Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+        }
     }
 }

+ 4 - 2
jme3-core/src/main/resources/Common/MatDefs/Blur/RadialBlur.j3md

@@ -1,6 +1,7 @@
 MaterialDef Radial Blur {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Texture2D Texture
         Color Color
@@ -10,13 +11,14 @@ MaterialDef Radial Blur {
     }
 
     Technique {
-        VertexShader GLSL300 GLSL120 GLSL150:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL300 GLSL120 GLSL150: Common/MatDefs/Blur/RadialBlur.frag
+        VertexShader GLSL300 GLSL150 GLSL120  :   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL120  : Common/MatDefs/Blur/RadialBlur.frag
 
         WorldParameters {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
         }
     }

+ 7 - 2
jme3-core/src/main/resources/Common/MatDefs/Blur/VGaussianBlur.j3md

@@ -1,6 +1,7 @@
 MaterialDef VGaussianBlur {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Texture2D Texture
         Float Size
@@ -8,10 +9,14 @@ MaterialDef VGaussianBlur {
     }
 
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Blur/VGaussianBlur.frag
+        VertexShader GLSL300 GLSL150 GLSL100  :   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100  : Common/MatDefs/Blur/VGaussianBlur.frag
 
         WorldParameters {
         }
+        
+        Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+        }
     }
 }

+ 4 - 15
jme3-core/src/main/resources/Common/MatDefs/Gui/Gui.j3md

@@ -1,37 +1,26 @@
 MaterialDef Default GUI {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D Texture
         Color Color (Color)
         Boolean VertexColor (UseVertexColor)
     }
 
     Technique {
-        VertexShader GLSL150:   Common/MatDefs/Gui/Gui.vert
-        FragmentShader GLSL150: Common/MatDefs/Gui/Gui.frag
+        VertexShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Gui/Gui.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Gui/Gui.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             TEXTURE : Texture
             VERTEX_COLOR : VertexColor
         }
     }
 
-    Technique {
-        VertexShader GLSL100:   Common/MatDefs/Gui/Gui.vert
-        FragmentShader GLSL100: Common/MatDefs/Gui/Gui.frag
-
-        WorldParameters {
-            WorldViewProjectionMatrix
-        }
-
-        Defines {
-            TEXTURE : Texture
-            VERTEX_COLOR : VertexColor
-        }
-    }
 
 }

+ 4 - 2
jme3-core/src/main/resources/Common/MatDefs/Hdr/LogLum.j3md

@@ -1,6 +1,7 @@
 MaterialDef Log Lum 2D {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D Texture
         Vector2 BlockSize
         Vector2 PixelSize
@@ -12,14 +13,15 @@ MaterialDef Log Lum 2D {
     }
 
     Technique {
-        VertexShader GLSL100:   Common/MatDefs/Gui/Gui.vert
-        FragmentShader GLSL100: Common/MatDefs/Hdr/LogLum.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Gui/Gui.vert
+        FragmentShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Hdr/LogLum.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             TEXTURE
             ENCODE_LUM : EncodeLum
             DECODE_LUM : DecodeLum

+ 4 - 2
jme3-core/src/main/resources/Common/MatDefs/Hdr/ToneMap.j3md

@@ -1,5 +1,6 @@
 MaterialDef Tone Mapper {
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D Texture
         Texture2D Lum
         Texture2D Lum2
@@ -9,14 +10,15 @@ MaterialDef Tone Mapper {
         Float Gamma
     }
     Technique {
-        VertexShader GLSL100:   Common/MatDefs/Gui/Gui.vert
-        FragmentShader GLSL100: Common/MatDefs/Hdr/ToneMap.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Gui/Gui.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Hdr/ToneMap.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             TEXTURE
         }
     }

+ 4 - 2
jme3-core/src/main/resources/Common/MatDefs/Light/Deferred.j3md

@@ -2,6 +2,7 @@
 MaterialDef Phong Lighting Deferred {
 
     MaterialParameters {
+        Int BoundDrawBuffer
 
         // Use more efficient algorithms to improve performance
         Boolean LowQuality
@@ -35,8 +36,8 @@ MaterialDef Phong Lighting Deferred {
     Technique {
         LightMode MultiPass
 
-        VertexShader GLSL100:   Common/MatDefs/Light/Deferred.vert
-        FragmentShader GLSL100: Common/MatDefs/Light/Deferred.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Light/Deferred.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Light/Deferred.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -46,6 +47,7 @@ MaterialDef Phong Lighting Deferred {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             ATTENUATION : Attenuation
             V_TANGENT : VTangent
             MINNAERT  : Minnaert

+ 2 - 0
jme3-core/src/main/resources/Common/MatDefs/Light/Deferred.vert

@@ -1,3 +1,5 @@
+#import "Common/ShaderLib/GLSLCompat.glsllib"
+
 varying vec2 texCoord;
 
 attribute vec3 inPosition;

+ 2 - 0
jme3-core/src/main/resources/Common/MatDefs/Light/GBuf.vert

@@ -1,3 +1,5 @@
+#import "Common/ShaderLib/GLSLCompat.glsllib"
+
 uniform mat4 g_WorldViewProjectionMatrix;
 uniform mat4 g_WorldMatrix;
 

+ 20 - 13
jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md

@@ -1,6 +1,7 @@
 MaterialDef Phong Lighting {
 
     MaterialParameters {
+        Int BoundDrawBuffer
 
         // Compute vertex lighting in the shader
         // For better performance
@@ -133,8 +134,8 @@ MaterialDef Phong Lighting {
     Technique {
         LightMode SinglePass
 
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150:   Common/MatDefs/Light/SPLighting.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/SPLighting.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Light/SPLighting.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/Light/SPLighting.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -146,7 +147,8 @@ MaterialDef Phong Lighting {
             ViewProjectionMatrix            
         }
 
-        Defines {           
+        Defines {  
+            BOUND_DRAW_BUFFER: BoundDrawBuffer         
             VERTEX_COLOR : UseVertexColor
             VERTEX_LIGHTING : VertexLighting           
             MATERIAL_COLORS : UseMaterialColors         
@@ -180,8 +182,8 @@ MaterialDef Phong Lighting {
 
         LightMode MultiPass
 
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150:   Common/MatDefs/Light/Lighting.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/Lighting.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Light/Lighting.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/Light/Lighting.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -194,6 +196,7 @@ MaterialDef Phong Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             VERTEX_COLOR : UseVertexColor
             VERTEX_LIGHTING : VertexLighting            
             MATERIAL_COLORS : UseMaterialColors
@@ -225,8 +228,8 @@ MaterialDef Phong Lighting {
 
     Technique PreShadow {
 
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150 :   Common/MatDefs/Shadow/PreShadow.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PreShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -236,6 +239,7 @@ MaterialDef Phong Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             DISCARD_ALPHA : AlphaDiscardThreshold
             NUM_BONES : NumberOfBones
             INSTANCING : UseInstancing
@@ -255,8 +259,8 @@ MaterialDef Phong Lighting {
 
 
     Technique PostShadow {
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150:   Common/MatDefs/Shadow/PostShadow.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PostShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -267,6 +271,7 @@ MaterialDef Phong Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HARDWARE_SHADOWS : HardwareShadows
             FILTER_MODE : FilterMode
             PCFEDGE : PCFEdge
@@ -292,8 +297,8 @@ MaterialDef Phong Lighting {
 
   Technique PreNormalPass {
 
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150 :   Common/MatDefs/SSAO/normal.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/SSAO/normal.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/SSAO/normal.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -304,6 +309,7 @@ MaterialDef Phong Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             DIFFUSEMAP_ALPHA : DiffuseMap
             NUM_BONES : NumberOfBones
             INSTANCING : UseInstancing
@@ -315,8 +321,8 @@ MaterialDef Phong Lighting {
 
     Technique Glow {
 
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150:   Common/MatDefs/Misc/Unshaded.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Misc/Unshaded.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/Light/Glow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -325,6 +331,7 @@ MaterialDef Phong Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             NEED_TEXCOORD1
             HAS_GLOWMAP : GlowMap
             HAS_GLOWCOLOR : GlowColor

+ 17 - 11
jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md

@@ -1,6 +1,7 @@
 MaterialDef PBR Lighting {
 
     MaterialParameters {
+        Int BoundDrawBuffer
 
         // Alpha threshold for fragment discarding
         Float AlphaDiscardThreshold (AlphaTestFallOff)
@@ -129,8 +130,8 @@ MaterialDef PBR Lighting {
     Technique {
         LightMode SinglePassAndImageBased
         
-        VertexShader GLSL300 GLSL110 GLSL150:   Common/MatDefs/Light/PBRLighting.vert
-        FragmentShader GLSL300 GLSL110 GLSL150: Common/MatDefs/Light/PBRLighting.frag
+        VertexShader GLSL300 GLSL150 GLSL110:   Common/MatDefs/Light/PBRLighting.vert
+        FragmentShader GLSL300 GLSL150 GLSL110: Common/MatDefs/Light/PBRLighting.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -141,7 +142,8 @@ MaterialDef PBR Lighting {
             ViewMatrix
         }
 
-        Defines {         
+        Defines {  
+            BOUND_DRAW_BUFFER: BoundDrawBuffer       
             BASECOLORMAP : BaseColorMap            
             NORMALMAP : NormalMap
             NORMALSCALE : NormalScale
@@ -176,8 +178,8 @@ MaterialDef PBR Lighting {
 
     Technique PreShadow {
 
-        VertexShader GLSL300 GLSL100 GLSL150 :   Common/MatDefs/Shadow/PreShadow.vert
-        FragmentShader GLSL300 GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadowPBR.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PreShadowPBR.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -187,6 +189,7 @@ MaterialDef PBR Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             DISCARD_ALPHA : AlphaDiscardThreshold
             NUM_BONES : NumberOfBones
             INSTANCING : UseInstancing
@@ -206,8 +209,8 @@ MaterialDef PBR Lighting {
 
 
     Technique PostShadow {
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150:   Common/MatDefs/Shadow/PostShadow.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadowPBR.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PostShadowPBR.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -217,6 +220,7 @@ MaterialDef PBR Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HARDWARE_SHADOWS : HardwareShadows
             FILTER_MODE : FilterMode
             PCFEDGE : PCFEdge
@@ -241,8 +245,8 @@ MaterialDef PBR Lighting {
 
     Technique PreNormalPass {
 
-        VertexShader GLSL100 :   Common/MatDefs/SSAO/normal.vert
-        FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag
+        VertexShader   GLSL300 GLSL150 GLSL100 :   Common/MatDefs/SSAO/normal.vert
+        FragmentShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/SSAO/normal.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -253,6 +257,7 @@ MaterialDef PBR Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             BASECOLORMAP_ALPHA : BaseColorMap            
             NUM_BONES : NumberOfBones
             INSTANCING : UseInstancing
@@ -264,8 +269,8 @@ MaterialDef PBR Lighting {
 
     Technique Glow {
 
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Misc/Unshaded.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Misc/Unshaded.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Light/Glow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -274,6 +279,7 @@ MaterialDef PBR Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             NEED_TEXCOORD1
             NUM_BONES : NumberOfBones
             INSTANCING : UseInstancing

+ 7 - 5
jme3-core/src/main/resources/Common/MatDefs/Misc/ColoredTextured.j3md

@@ -2,20 +2,22 @@ Exception This material definition is deprecated. Please use Unshaded.j3md inste
 MaterialDef Colored Textured {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D ColorMap
         Color Color (Color)
     }
 
     Technique {
-        VertexShader GLSL100:   Common/MatDefs/Misc/ColoredTextured.vert
-        FragmentShader GLSL100: Common/MatDefs/Misc/ColoredTextured.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Misc/ColoredTextured.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Misc/ColoredTextured.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
         }
+        Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+        }
     }
 
-    Technique {
-    }
-
+ 
 }

+ 2 - 0
jme3-core/src/main/resources/Common/MatDefs/Misc/ColoredTextured.vert

@@ -1,3 +1,5 @@
+#import "Common/ShaderLib/GLSLCompat.glsllib"
+
 uniform mat4 g_WorldViewProjectionMatrix;
 
 attribute vec3 inPosition;

+ 13 - 8
jme3-core/src/main/resources/Common/MatDefs/Misc/Particle.j3md

@@ -1,6 +1,7 @@
 MaterialDef Point Sprite {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D Texture
         Float Quadratic
         Boolean PointSprite
@@ -24,8 +25,8 @@ MaterialDef Point Sprite {
         // Point sprite should be used if running on ES2, but crash
         // if on desktop (because its not supported by HW)
 
-        VertexShader   GLSL100 GLSL100 GLSL150 : Common/MatDefs/Misc/Particle.vert
-        FragmentShader GLSL100 GLSL120 GLSL150 : Common/MatDefs/Misc/Particle.frag
+        VertexShader   GLSL300 GLSL150 GLSL120 GLSL100: Common/MatDefs/Misc/Particle.vert
+        FragmentShader GLSL300 GLSL150 GLSL120 GLSL100: Common/MatDefs/Misc/Particle.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -41,6 +42,7 @@ MaterialDef Point Sprite {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             USE_TEXTURE : Texture
             POINT_SPRITE : PointSprite
         }
@@ -48,8 +50,8 @@ MaterialDef Point Sprite {
 
     Technique PreShadow {
 
-        VertexShader GLSL100 GLSL150 :   Common/MatDefs/Shadow/PreShadow.vert
-        FragmentShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PreShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -59,6 +61,7 @@ MaterialDef Point Sprite {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             COLOR_MAP : Texture
         }
 
@@ -74,8 +77,8 @@ MaterialDef Point Sprite {
 
     Technique SoftParticles{
 
-        VertexShader  GLSL100 GLSL150 : Common/MatDefs/Misc/SoftParticle.vert
-        FragmentShader GLSL120 GLSL150 : Common/MatDefs/Misc/SoftParticle.frag
+        VertexShader   GLSL300 GLSL150 GLSL100: Common/MatDefs/Misc/SoftParticle.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Misc/SoftParticle.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -91,6 +94,7 @@ MaterialDef Point Sprite {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             USE_TEXTURE : Texture
             POINT_SPRITE : PointSprite
             RESOLVE_DEPTH_MS : NumSamplesDepth
@@ -99,14 +103,15 @@ MaterialDef Point Sprite {
 
    Technique Glow {
 
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Misc/Unshaded.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Misc/Unshaded.vert
+        FragmentShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Light/Glow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             NEED_TEXCOORD1
             HAS_GLOWMAP : GlowMap
             HAS_GLOWCOLOR : GlowColor

+ 4 - 2
jme3-core/src/main/resources/Common/MatDefs/Misc/ShowNormals.j3md

@@ -1,12 +1,13 @@
 MaterialDef Debug Normals {
     MaterialParameters {
+        Int BoundDrawBuffer
         // For instancing
         Boolean UseInstancing
     }
 
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Misc/ShowNormals.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Misc/ShowNormals.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Misc/ShowNormals.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Misc/ShowNormals.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -16,6 +17,7 @@ MaterialDef Debug Normals {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             INSTANCING : UseInstancing
         }
     }

+ 4 - 2
jme3-core/src/main/resources/Common/MatDefs/Misc/Sky.j3md

@@ -1,13 +1,14 @@
 MaterialDef Sky Plane {
     MaterialParameters {
+        Int BoundDrawBuffer
         TextureCubeMap Texture
         Boolean SphereMap
         Boolean EquirectMap
         Vector3 NormalScale
     }
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Misc/Sky.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Misc/Sky.frag
+        VertexShader    GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Misc/Sky.vert
+        FragmentShader  GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Misc/Sky.frag
 
         WorldParameters {
             ViewMatrix
@@ -16,6 +17,7 @@ MaterialDef Sky Plane {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             SPHERE_MAP : SphereMap
             EQUIRECT_MAP : EquirectMap
         }

+ 4 - 2
jme3-core/src/main/resources/Common/MatDefs/Misc/SkyNonCube.j3md

@@ -1,13 +1,14 @@
 MaterialDef Sky Plane {
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D Texture
         Boolean SphereMap
         Boolean EquirectMap
         Vector3 NormalScale
     }
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Misc/Sky.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Misc/Sky.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Misc/Sky.vert
+        FragmentShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Misc/Sky.frag
 
         WorldParameters {
             ViewMatrix
@@ -16,6 +17,7 @@ MaterialDef Sky Plane {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             SPHERE_MAP : SphereMap
             EQUIRECT_MAP : EquirectMap
         }

+ 16 - 10
jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md

@@ -1,6 +1,7 @@
 MaterialDef Unshaded {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D ColorMap
         Texture2D LightMap
         Color Color (Color)
@@ -65,8 +66,8 @@ MaterialDef Unshaded {
     }
 
     Technique {
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150:   Common/MatDefs/Misc/Unshaded.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Misc/Unshaded.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100 : Common/MatDefs/Misc/Unshaded.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -75,6 +76,7 @@ MaterialDef Unshaded {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             INSTANCING : UseInstancing
             SEPARATE_TEXCOORD : SeparateTexCoord
             HAS_COLORMAP : ColorMap
@@ -92,8 +94,8 @@ MaterialDef Unshaded {
 
     Technique PreNormalPass {
 
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150 :   Common/MatDefs/SSAO/normal.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/SSAO/normal.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/SSAO/normal.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -104,6 +106,7 @@ MaterialDef Unshaded {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             COLORMAP_ALPHA : ColorMap
             NUM_BONES : NumberOfBones
             INSTANCING : UseInstancing
@@ -114,8 +117,8 @@ MaterialDef Unshaded {
 
     Technique PreShadow {
 
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150 :   Common/MatDefs/Shadow/PreShadow.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -125,6 +128,7 @@ MaterialDef Unshaded {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             COLOR_MAP : ColorMap
             DISCARD_ALPHA : AlphaDiscardThreshold
             NUM_BONES : NumberOfBones
@@ -145,8 +149,8 @@ MaterialDef Unshaded {
 
 
     Technique PostShadow {
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150:   Common/MatDefs/Shadow/PostShadow.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
+        VertexShader    GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
+        FragmentShader  GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -156,6 +160,7 @@ MaterialDef Unshaded {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HARDWARE_SHADOWS : HardwareShadows
             FILTER_MODE : FilterMode
             PCFEDGE : PCFEdge
@@ -181,8 +186,8 @@ MaterialDef Unshaded {
 
     Technique Glow {
 
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150:   Common/MatDefs/Misc/Unshaded.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Misc/Unshaded.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Light/Glow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -191,6 +196,7 @@ MaterialDef Unshaded {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             NEED_TEXCOORD1
             HAS_GLOWMAP : GlowMap
             HAS_GLOWCOLOR : GlowColor

+ 4 - 2
jme3-core/src/main/resources/Common/MatDefs/Shadow/BasicPostShadow.j3md

@@ -1,13 +1,14 @@
 MaterialDef Basic Post Shadow {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D ShadowMap
         Matrix4 LightViewProjectionMatrix
     }
 
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Shadow/BasicPostShadow.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Shadow/BasicPostShadow.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/BasicPostShadow.vert
+        FragmentShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/BasicPostShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -15,6 +16,7 @@ MaterialDef Basic Post Shadow {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             NO_SHADOW2DPROJ
         }
 

+ 4 - 2
jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow.j3md

@@ -1,6 +1,7 @@
 MaterialDef Post Shadow {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int FilterMode
         Boolean HardwareShadows
 
@@ -35,8 +36,8 @@ MaterialDef Post Shadow {
     }
 
     Technique {
-        VertexShader GLSL310 GLSL300 GLSL100 GLSL150:   Common/MatDefs/Shadow/PostShadow.vert
-        FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PostShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -44,6 +45,7 @@ MaterialDef Post Shadow {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HARDWARE_SHADOWS : HardwareShadows
             FILTER_MODE : FilterMode
             PCFEDGE : PCFEdge

+ 7 - 4
jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.j3md

@@ -1,6 +1,7 @@
 MaterialDef Post Shadow {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int FilterMode
         Boolean HardwareShadows
 
@@ -42,14 +43,15 @@ MaterialDef Post Shadow {
     }
 
     Technique {
-        VertexShader GLSL310 GLSL150:   Common/MatDefs/Shadow/PostShadowFilter.vert
-        FragmentShader GLSL310 GLSL150: Common/MatDefs/Shadow/PostShadowFilter15.frag
+        VertexShader   GLSL310 GLSL300 GLSL150 :   Common/MatDefs/Shadow/PostShadowFilter.vert
+        FragmentShader GLSL310 GLSL300 GLSL150 :   Common/MatDefs/Shadow/PostShadowFilter15.frag
 
         WorldParameters {
             ResolutionInverse
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
             RESOLVE_DEPTH_MS : NumSamplesDepth
             HARDWARE_SHADOWS : HardwareShadows
@@ -65,14 +67,15 @@ MaterialDef Post Shadow {
     }
 
     Technique {
-        VertexShader GLSL100:   Common/MatDefs/Shadow/PostShadowFilter.vert
-        FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadowFilter.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadowFilter.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PostShadowFilter.frag
 
         WorldParameters {
             ResolutionInverse
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HARDWARE_SHADOWS : HardwareShadows
             FILTER_MODE : FilterMode
             PCFEDGE : PCFEdge

+ 10 - 2
jme3-core/src/main/resources/Common/MatDefs/Shadow/PreShadow.j3md

@@ -1,7 +1,15 @@
 MaterialDef Pre Shadow {
+    MaterialParameters {
+        Int BoundDrawBuffer
+    }
+
     Technique {
-        VertexShader GLSL100 GLSL150 :   Common/MatDefs/Shadow/PreShadow.vert
-        FragmentShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.vert
+        FragmentShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.frag
+
+        Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+        }
 
         WorldParameters {
             WorldViewProjectionMatrix

+ 32 - 4
jme3-core/src/main/resources/Common/ShaderLib/GLSLCompat.glsllib

@@ -1,3 +1,17 @@
+#ifdef FRAGMENT_SHADER
+      precision highp float;
+      precision highp int;
+      precision highp sampler2DArray;
+      precision highp sampler2DShadow;
+      precision highp samplerCube;
+      precision highp sampler3D;
+      precision highp sampler2D;
+      #if __VERSION__ >= 310
+        precision highp sampler2DMS;
+      #endif
+
+#endif
+
 #if defined GL_ES
 #  define hfloat highp float
 #  define hvec2  highp vec2
@@ -19,11 +33,25 @@
 #endif
 
 #if __VERSION__ >= 130
-#  ifdef GL_ES
-out highp vec4 outFragColor;
-#  else
-out vec4 outFragColor;
+
+#ifdef FRAGMENT_SHADER
+  #ifdef GL_ES
+    #ifdef BOUND_DRAW_BUFFER
+      #for i=0..15 ( #if $i<=BOUND_DRAW_BUFFER  $0 #endif ) 
+        #if BOUND_DRAW_BUFFER == $i
+          layout( location = $i ) out highp vec4 outFragColor;
+        #else
+          layout( location = $i ) out highp vec4 outNOP$i;
+        #endif
+      #endfor
+    #else
+      out highp vec4 outFragColor;
+    #endif
+  #else
+    out vec4 outFragColor;
+  #endif
 #endif
+
 #  define texture1D texture
 #  define texture2D texture
 #  define texture3D texture

+ 1 - 1
jme3-core/src/test/java/com/jme3/material/MaterialMatParamTest.java

@@ -449,7 +449,7 @@ public class MaterialMatParamTest {
             MaterialMatParamTest.this.usedTextures[unit] = texture;
         }
     };
-    private final RenderManager renderManager = new RenderManager(renderer);
+    private final RenderManager renderManager = TestUtil.createRenderManager(renderer);
 
     private boolean evaluated = false;
     private Shader usedShader = null;

+ 1 - 1
jme3-core/src/test/java/com/jme3/material/MaterialTest.java

@@ -104,7 +104,7 @@ public class MaterialTest {
 
         material.selectTechnique("Default", renderManager);
 
-        checkRequiredCaps(Caps.GLSL100, Caps.GLSL120);
+        checkRequiredCaps(Caps.GLSL120);
     }
 
     @Test

+ 10 - 2
jme3-core/src/test/java/com/jme3/system/TestUtil.java

@@ -35,6 +35,8 @@ import com.jme3.asset.AssetConfig;
 import com.jme3.asset.AssetManager;
 import com.jme3.asset.DesktopAssetManager;
 import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.Renderer;
+
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -55,7 +57,13 @@ public class TestUtil {
         return new DesktopAssetManager(true);
     }
     
-    public static RenderManager createRenderManager() {
-        return new RenderManager(new NullRenderer());
+    public static RenderManager createRenderManager() {        
+        return createRenderManager(new NullRenderer());
+    }
+
+    public static RenderManager createRenderManager(Renderer renderer) {
+        RenderManager rm = new RenderManager(renderer);
+        rm.setPassDrawBufferTargetIdToShaders(false);
+        return rm;
     }
 }

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/BloomExtract.j3md

@@ -1,6 +1,7 @@
 MaterialDef Bloom {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Texture2D Texture
         Float ExposurePow
@@ -10,13 +11,14 @@ MaterialDef Bloom {
     }
 
     Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/bloomExtract.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Post/bloomExtract.frag
 
         WorldParameters {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HAS_GLOWMAP : GlowMap
             DO_EXTRACT : Extract
             RESOLVE_MS : NumSamples

+ 5 - 3
jme3-effects/src/main/resources/Common/MatDefs/Post/BloomFinal.j3md

@@ -1,20 +1,22 @@
 MaterialDef Bloom Final {
 
     MaterialParameters {
-          Int NumSamples
+        Int BoundDrawBuffer
+        Int NumSamples
         Texture2D Texture
         Texture2D BloomTex
         Float BloomIntensity
     }
 
     Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/bloomFinal.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Post/bloomFinal.frag
 
         WorldParameters {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
         }
     }

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/CartoonEdge.j3md

@@ -1,6 +1,7 @@
 MaterialDef Cartoon Edge {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
@@ -16,8 +17,8 @@ MaterialDef Cartoon Edge {
     }
 
      Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/CartoonEdge.frag
+        VertexShader   GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Post/CartoonEdge.frag
 
         WorldParameters {
             WorldViewMatrix
@@ -25,6 +26,7 @@ MaterialDef Cartoon Edge {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
             RESOLVE_DEPTH_MS : NumSamplesDepth
         }

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/Compose.j3md

@@ -1,6 +1,7 @@
 MaterialDef Default GUI {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
@@ -8,13 +9,14 @@ MaterialDef Default GUI {
     }
 
     Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/Compose.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Post/Compose.frag
 
         WorldParameters {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
         }
 

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/ContrastAdjustment.frag

@@ -37,9 +37,11 @@
  * Then a power law is applied, using the exponent for each channel.
  * Finally, the output value is scaled linearly, using the scaling factor for each channel.
  *
- * Supports GLSL100 GLSL110 GLSL120 GLSL130.
  */
 
+#import "Common/ShaderLib/GLSLCompat.glsllib"
+#import "Common/ShaderLib/MultiSample.glsllib"
+
 //constant inputs from java source
 uniform float m_redChannelExponent;
 uniform float m_greenChannelExponent;
@@ -55,7 +57,7 @@ uniform float m_lowerLimit;
 uniform float m_upperLimit;
 
 //container for the input from post.vert
-uniform sampler2D m_Texture;
+uniform COLORTEXTURE m_Texture;
 
 //varying input from post.vert vertex shader
 varying vec2 texCoord;

+ 10 - 6
jme3-effects/src/main/resources/Common/MatDefs/Post/ContrastAdjustment.j3md

@@ -4,6 +4,7 @@
 MaterialDef ColorAdjustmentFilter {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Texture2D Texture
         Float redChannelExponent
@@ -15,14 +16,17 @@ MaterialDef ColorAdjustmentFilter {
         Float greenChannelScale
         Float blueChannelScale
     }
+ 
 
     Technique {
-        VertexShader GLSL150 GLSL300 GLSL310 GLSL320:   Common/MatDefs/Post/Post15.vert
-        FragmentShader GLSL150 GLSL300 GLSL310 GLSL320: Common/MatDefs/Post/ContrastAdjustment15.frag
-    }
+        VertexShader    GLSL300 GLSL150 GLSL100:    Common/MatDefs/Post/Post.vert
+        FragmentShader  GLSL300 GLSL150 GLSL100:  Common/MatDefs/Post/ContrastAdjustment.frag
+        WorldParameters {
+        }
 
-    Technique {
-        VertexShader  GLSL100 GLSL110 GLSL120 GLSL130:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL100 GLSL110 GLSL120 GLSL130:  Common/MatDefs/Post/ContrastAdjustment.frag
+        Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+            NUM_SAMPLES : NumSamples
+        }
     }
 }

+ 0 - 95
jme3-effects/src/main/resources/Common/MatDefs/Post/ContrastAdjustment15.frag

@@ -1,95 +0,0 @@
-/*
- * Copyright (c) 2009-2021 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- *   may be used to endorse or promote products derived from this software
- *   without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Used by ContrastAdjustment.j3md to adjust the color channels.
- *
- * First, the input range is normalized to upper and lower limits.
- * Then a power law is applied, using the exponent for each channel.
- * Finally, the output value is scaled linearly, using the scaling factor for each channel.
- *
- * Supports glsl150 and glsl150+ including android GLES glsl300, glsl310 and glsl320.
- */
-
-#import "Common/ShaderLib/GLSLCompat.glsllib"
-#import "Common/ShaderLib/MultiSample.glsllib"
-
-//constant inputs from java source
-uniform float m_redChannelExponent;
-uniform float m_greenChannelExponent;
-uniform float m_blueChannelExponent;
-
-//final scale values
-uniform float m_redChannelScale;
-uniform float m_greenChannelScale;
-uniform float m_blueChannelScale;
-
-//input range
-uniform float m_lowerLimit;
-uniform float m_upperLimit;
-
-//container for the input from post15.vert
-uniform COLORTEXTURE m_Texture;
-
-//varying input from post15.vert vertex shader
-in vec2 texCoord;
-
-//the output color
-out vec4 fragColor;
-
-void main() {
-    //get the color from a 2d sampler.
-    vec4 color = texture2D(m_Texture, texCoord);
-
-    //apply the color transfer function.
-
-    //1) adjust the channels input range
-    color.rgb = (color.rgb - vec3(m_lowerLimit)) / (vec3(m_upperLimit) - vec3(m_lowerLimit));
-
-    // avoid negative levels
-    color.r = max(color.r, 0.0);
-    color.g = max(color.g, 0.0);
-    color.b = max(color.b, 0.0);
-
-    //2) apply transfer functions on different channels.
-    color.r = pow(color.r, m_redChannelExponent);
-    color.g = pow(color.g, m_greenChannelExponent);
-    color.b = pow(color.b, m_blueChannelExponent);
-
-    //3) scale the output levels
-    color.r = color.r * m_redChannelScale;
-    color.b = color.b * m_blueChannelScale;
-    color.g = color.g * m_greenChannelScale;
-
-    //4) process the textures colors.
-    fragColor = color;
-}

+ 7 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/CrossHatch.j3md

@@ -1,6 +1,7 @@
 MaterialDef CrossHatch {
  
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Texture2D Texture;
         Vector4 LineColor;
@@ -18,11 +19,15 @@ MaterialDef CrossHatch {
     }
  
     Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/CrossHatch.frag
+        VertexShader   GLSL300 GLSL150 GLSL100 : Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/Post/CrossHatch.frag
  
         WorldParameters {
         }
+
+        Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+        }
     }
 
 }

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/DepthOfField.j3md

@@ -1,6 +1,7 @@
 MaterialDef Depth Of Field {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
@@ -14,14 +15,15 @@ MaterialDef Depth Of Field {
     }
 
     Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/DepthOfField.frag
+        VertexShader   GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/Post/DepthOfField.frag
 
         WorldParameters {
             FrustumNearFar
         }
         
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
             RESOLVE_DEPTH_MS : NumSamplesDepth
             BLUR_THRESHOLD : BlurThreshold

+ 7 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/FXAA.j3md

@@ -1,5 +1,6 @@
 MaterialDef FXAA {
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Texture2D Texture
         Float SubPixelShift
@@ -8,10 +9,14 @@ MaterialDef FXAA {
         Float ReduceMul
     }
     Technique {
-        VertexShader GLSL300 GLSL100 GLSL150:   Common/MatDefs/Post/FXAA.vert
-        FragmentShader GLSL300 GLSL100 GLSL150: Common/MatDefs/Post/FXAA.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Post/FXAA.vert
+        FragmentShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Post/FXAA.frag
         WorldParameters {
             ResolutionInverse
         }
+
+        Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+        }
     }
 }

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/Fade.j3md

@@ -1,19 +1,21 @@
 MaterialDef Fade {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Texture2D Texture
         Float Value
     }
 
     Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/Fade.frag
+        VertexShader   GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Post/Fade.frag
 
         WorldParameters {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
         }
     }

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/Fog.j3md

@@ -1,6 +1,7 @@
 MaterialDef Fade {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
@@ -11,13 +12,14 @@ MaterialDef Fade {
     }
 
     Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/Fog.frag
+        VertexShader   GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Post/Fog.frag
 
         WorldParameters {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
             RESOLVE_DEPTH_MS : NumSamplesDepth
         }

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/LightScattering.j3md

@@ -1,5 +1,6 @@
 MaterialDef Light Scattering {
- MaterialParameters {
+    MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
@@ -14,13 +15,14 @@ MaterialDef Light Scattering {
     }
 
     Technique {
-        VertexShader GLSL300 GLSL150 GLSL120:   Common/MatDefs/Post/Post.vert
+        VertexShader   GLSL300 GLSL150 GLSL120:   Common/MatDefs/Post/Post.vert
         FragmentShader GLSL300 GLSL150 GLSL120: Common/MatDefs/Post/LightScattering.frag
 
         WorldParameters {          
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
             RESOLVE_DEPTH_MS : NumSamplesDepth
             DISPLAY: Display

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/Overlay.j3md

@@ -1,6 +1,7 @@
 MaterialDef Default GUI {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
@@ -8,13 +9,14 @@ MaterialDef Default GUI {
     }
 
     Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/Overlay.frag
+        VertexShader   GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/Post/Overlay.frag
 
         WorldParameters {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
         }
 

+ 2 - 0
jme3-effects/src/main/resources/Common/MatDefs/Post/Post15.vert

@@ -1,3 +1,5 @@
+#import "Common/ShaderLib/GLSLCompat.glsllib"
+
 in vec4 inPosition;
 in vec2 inTexCoord;
 

+ 5 - 3
jme3-effects/src/main/resources/Common/MatDefs/Post/Posterization.j3md

@@ -1,6 +1,7 @@
 MaterialDef Posterization {
  
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture;
@@ -10,14 +11,15 @@ MaterialDef Posterization {
     }
  
     Technique {
-        VertexShader GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL150 GLSL100: Common/MatDefs/Post/Posterization.frag
+        VertexShader   GLSL300 GLSL150 GLSL100 :   Common/MatDefs/Post/Post.vert
+        FragmentShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/Post/Posterization.frag
  
         WorldParameters {
         }
 
         Defines {
-           RESOLVE_MS : NumSamples
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+            RESOLVE_MS : NumSamples
         }
 
     }

+ 4 - 2
jme3-effects/src/main/resources/Common/MatDefs/Post/ToneMap.j3md

@@ -1,6 +1,7 @@
 MaterialDef Default GUI {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
@@ -8,13 +9,14 @@ MaterialDef Default GUI {
     }
 
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Post/Post.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Post/ToneMap.frag
+        VertexShader     GLSL300 GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
+        FragmentShader   GLSL300 GLSL150 GLSL100: Common/MatDefs/Post/ToneMap.frag
 
         WorldParameters {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             NUM_SAMPLES : NumSamples
         }
     }

+ 3 - 1
jme3-effects/src/main/resources/Common/MatDefs/SSAO/ssao.j3md

@@ -1,6 +1,7 @@
 MaterialDef SSAO {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
@@ -18,7 +19,7 @@ MaterialDef SSAO {
     }
 
     Technique {
-        VertexShader GLSL300 GLSL150 GLSL120:   Common/MatDefs/Post/Post.vert
+        VertexShader   GLSL300 GLSL150 GLSL120:   Common/MatDefs/Post/Post.vert
         FragmentShader GLSL300 GLSL150 GLSL120: Common/MatDefs/SSAO/ssao.frag
 
         WorldParameters {
@@ -28,6 +29,7 @@ MaterialDef SSAO {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
             RESOLVE_DEPTH_MS : NumSamplesDepth
             APPROXIMATE_NORMALS : ApproximateNormals

+ 3 - 1
jme3-effects/src/main/resources/Common/MatDefs/SSAO/ssaoBlur.j3md

@@ -1,6 +1,7 @@
 MaterialDef SSAOBlur {
 
-    MaterialParameters {       
+    MaterialParameters {     
+        Int BoundDrawBuffer  
         Int NumSamples
         Int NumSamplesDepth
         Texture2D Texture
@@ -22,6 +23,7 @@ MaterialDef SSAOBlur {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             USE_AO : UseAo
             USE_ONLY_AO : UseOnlyAo
             RESOLVE_MS : NumSamples

+ 7 - 2
jme3-effects/src/main/resources/Common/MatDefs/Water/SimpleWater.j3md

@@ -1,6 +1,7 @@
 MaterialDef Simple Water {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D water_reflection
         Texture2D water_refraction
         Texture2D water_depthmap
@@ -18,8 +19,8 @@ MaterialDef Simple Water {
     }
 
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Water/simple_water.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Water/simple_water.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Water/simple_water.vert
+        FragmentShader GLSL300 GLSL150 GLSL100 : Common/MatDefs/Water/simple_water.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -27,5 +28,9 @@ MaterialDef Simple Water {
             Resolution
             CameraPosition
         }
+        Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+        }
+        
     }
 }

+ 3 - 1
jme3-effects/src/main/resources/Common/MatDefs/Water/Water.j3md

@@ -1,6 +1,7 @@
 MaterialDef Advanced Water {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D FoamMap
@@ -59,7 +60,8 @@ MaterialDef Advanced Water {
         }
 
         Defines {
-          RESOLVE_MS : NumSamples
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+            RESOLVE_MS : NumSamples
             RESOLVE_DEPTH_MS : NumSamplesDepth
             ENABLE_RIPPLES : UseRipples
             ENABLE_HQ_SHORELINE : UseHQShoreline

+ 15 - 0
jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java

@@ -789,5 +789,20 @@ public class IosGL implements GL, GL2, GLES_30, GLExt, GLFbo {
         JmeIosGLES.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
     }
 
+    @Override
+    public void glBindVertexArray(int array) {
+        throw new UnsupportedOperationException("Unimplemented method 'glBindVertexArray'");
+    }
+
+    @Override
+    public void glDeleteVertexArrays(IntBuffer arrays) {
+        throw new UnsupportedOperationException("Unimplemented method 'glDeleteVertexArrays'");
+    }
+
+    @Override
+    public void glGenVertexArrays(IntBuffer arrays) {
+        throw new UnsupportedOperationException("Unimplemented method 'glGenVertexArrays'");
+    }
+
 
 }

+ 2 - 2
jme3-niftygui/src/main/resources/Common/MatDefs/Nifty/NiftyQuad.j3md

@@ -5,8 +5,8 @@ MaterialDef Default GUI {
     }
 
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Nifty/NiftyQuad.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Nifty/NiftyQuad.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Nifty/NiftyQuad.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Nifty/NiftyQuad.frag
 
         WorldParameters {
             WorldViewProjectionMatrix

+ 2 - 2
jme3-niftygui/src/main/resources/Common/MatDefs/Nifty/NiftyQuadGrad.j3md

@@ -4,8 +4,8 @@ MaterialDef Default GUI {
     }
 
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Nifty/NiftyQuadGrad.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Nifty/NiftyQuadGrad.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Nifty/NiftyQuadGrad.vert
+        FragmentShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Nifty/NiftyQuadGrad.frag
 
         WorldParameters {
             WorldViewProjectionMatrix

+ 2 - 2
jme3-niftygui/src/main/resources/Common/MatDefs/Nifty/NiftyTex.j3md

@@ -6,8 +6,8 @@ MaterialDef Default GUI {
     }
 
     Technique {
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Nifty/NiftyTex.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Nifty/NiftyTex.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Nifty/NiftyTex.vert
+        FragmentShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/Nifty/NiftyTex.frag
 
         WorldParameters {
             WorldViewProjectionMatrix

+ 10 - 6
jme3-terrain/src/main/resources/Common/MatDefs/Terrain/AdvancedPBRTerrain.j3md

@@ -2,6 +2,7 @@
 MaterialDef Advanced PBR Terrain {
 
     MaterialParameters {
+        Int BoundDrawBuffer
 
     
         Boolean UseVertexColorsAsSunIntensity //set true to make the vertex color's R channel how exposed a vertex is to the sun
@@ -255,8 +256,8 @@ MaterialDef Advanced PBR Terrain {
 
         LightMode SinglePassAndImageBased
 
-        VertexShader  GLSL150:   Common/MatDefs/Terrain/PBRTerrain.vert
-        FragmentShader GLSL150: Common/MatDefs/Terrain/AdvancedPBRTerrain.frag
+        VertexShader   GLSL300 GLSL150 :   Common/MatDefs/Terrain/PBRTerrain.vert
+        FragmentShader GLSL300 GLSL150 : Common/MatDefs/Terrain/AdvancedPBRTerrain.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -270,6 +271,7 @@ MaterialDef Advanced PBR Terrain {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
                 
             AFFLICTIONTEXTURE : AfflictionAlphaMap
             AFFLICTIONALBEDOMAP: SplatAlbedoMap 
@@ -340,8 +342,8 @@ MaterialDef Advanced PBR Terrain {
 
     Technique PreShadow {
 
-        VertexShader GLSL100 GLSL150 :   Common/MatDefs/Shadow/PreShadow.vert
-        FragmentShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PreShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -351,6 +353,7 @@ MaterialDef Advanced PBR Terrain {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             DISCARD_ALPHA : AlphaDiscardThreshold
             NUM_BONES : NumberOfBones
             INSTANCING : UseInstancing
@@ -368,8 +371,8 @@ MaterialDef Advanced PBR Terrain {
 
 
     Technique PostShadow{
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Shadow/PostShadow.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
+        VertexShader    GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
+        FragmentShader  GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PostShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -379,6 +382,7 @@ MaterialDef Advanced PBR Terrain {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HARDWARE_SHADOWS : HardwareShadows
             FILTER_MODE : FilterMode
             PCFEDGE : PCFEdge

+ 7 - 2
jme3-terrain/src/main/resources/Common/MatDefs/Terrain/HeightBasedTerrain.j3md

@@ -11,6 +11,7 @@ MaterialDef Terrain {
         // slopeTileFactor: the texture scale for slopes
         // terrainSize: the total size of the terrain (used for scaling the texture)
 	MaterialParameters {
+		Int BoundDrawBuffer
 		Texture2D region1ColorMap
 		Texture2D region2ColorMap
 		Texture2D region3ColorMap
@@ -25,14 +26,18 @@ MaterialDef Terrain {
 	}
 
 	Technique {
-		VertexShader GLSL100 GLSL150:   Common/MatDefs/Terrain/HeightBasedTerrain.vert
-		FragmentShader GLSL100 GLSL150: Common/MatDefs/Terrain/HeightBasedTerrain.frag
+		VertexShader    GLSL300 GLSL150 GLSL100:   Common/MatDefs/Terrain/HeightBasedTerrain.vert
+		FragmentShader  GLSL300 GLSL150 GLSL100: Common/MatDefs/Terrain/HeightBasedTerrain.frag
 
 		WorldParameters {
 			WorldViewProjectionMatrix
 			WorldMatrix
 			NormalMatrix
 		}
+		
+		Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+        }
 	}
 
     Technique {

+ 10 - 6
jme3-terrain/src/main/resources/Common/MatDefs/Terrain/PBRTerrain.j3md

@@ -2,6 +2,7 @@
 MaterialDef PBR Terrain {
 
     MaterialParameters {
+        Int BoundDrawBuffer
 
 
         Boolean UseVertexColorsAsSunIntensity //set true to make the vertex color's R channel how exposed a vertex is to the sun
@@ -228,8 +229,8 @@ MaterialDef PBR Terrain {
 
         LightMode SinglePassAndImageBased
 
-        VertexShader GLSL100 GLSL130 GLSL150:   Common/MatDefs/Terrain/PBRTerrain.vert
-        FragmentShader GLSL100 GLSL130 GLSL150: Common/MatDefs/Terrain/PBRTerrain.frag
+        VertexShader    GLSL300 GLSL150 GLSL130 GLSL100:   Common/MatDefs/Terrain/PBRTerrain.vert
+        FragmentShader  GLSL300 GLSL150 GLSL130 GLSL100: Common/MatDefs/Terrain/PBRTerrain.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -243,6 +244,7 @@ MaterialDef PBR Terrain {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
                 
             TILELOCATION : TileLocation
             AFFLICTIONTEXTURE : AfflictionAlphaMap
@@ -318,8 +320,8 @@ MaterialDef PBR Terrain {
 
     Technique PreShadow {
 
-        VertexShader GLSL100 GLSL150 :   Common/MatDefs/Shadow/PreShadow.vert
-        FragmentShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PreShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -329,6 +331,7 @@ MaterialDef PBR Terrain {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             DISCARD_ALPHA : AlphaDiscardThreshold
             NUM_BONES : NumberOfBones
             INSTANCING : UseInstancing
@@ -346,8 +349,8 @@ MaterialDef PBR Terrain {
 
 
     Technique PostShadow{
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Shadow/PostShadow.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
+        VertexShader     GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
+        FragmentShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -357,6 +360,7 @@ MaterialDef PBR Terrain {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HARDWARE_SHADOWS : HardwareShadows
             FILTER_MODE : FilterMode
             PCFEDGE : PCFEdge

+ 4 - 2
jme3-terrain/src/main/resources/Common/MatDefs/Terrain/Terrain.j3md

@@ -1,6 +1,7 @@
 MaterialDef Terrain {
 
 	MaterialParameters {
+		Int BoundDrawBuffer
 
         // use tri-planar mapping
         Boolean useTriPlanarMapping
@@ -15,14 +16,15 @@ MaterialDef Terrain {
 	}
 
 	Technique {
-		VertexShader GLSL100 GLSL150:   Common/MatDefs/Terrain/Terrain.vert
-		FragmentShader GLSL100 GLSL150: Common/MatDefs/Terrain/Terrain.frag
+		VertexShader    GLSL300 GLSL150 GLSL100:   Common/MatDefs/Terrain/Terrain.vert
+		FragmentShader  GLSL300 GLSL150 GLSL100: Common/MatDefs/Terrain/Terrain.frag
 		
 		WorldParameters {
 			WorldViewProjectionMatrix
 		}
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             TRI_PLANAR_MAPPING : useTriPlanarMapping
         }
 	}

+ 16 - 10
jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md

@@ -2,6 +2,7 @@
 MaterialDef Terrain Lighting {
 
     MaterialParameters {
+        Int BoundDrawBuffer
 
         // use tri-planar mapping
         Boolean useTriPlanarMapping
@@ -108,8 +109,8 @@ MaterialDef Terrain Lighting {
 
         LightMode MultiPass
 
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Terrain/TerrainLighting.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Terrain/TerrainLighting.frag
+        VertexShader    GLSL300 GLSL150 GLSL100:   Common/MatDefs/Terrain/TerrainLighting.vert
+        FragmentShader  GLSL300 GLSL150 GLSL100:   Common/MatDefs/Terrain/TerrainLighting.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -119,6 +120,7 @@ MaterialDef Terrain Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             TRI_PLANAR_MAPPING : useTriPlanarMapping
             TERRAIN_GRID : isTerrainGrid
             WARDISO   : WardIso
@@ -173,8 +175,8 @@ MaterialDef Terrain Lighting {
 
         LightMode SinglePass
 
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Terrain/SPTerrainLighting.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Terrain/SPTerrainLighting.frag
+        VertexShader    GLSL300 GLSL150 GLSL100:   Common/MatDefs/Terrain/SPTerrainLighting.vert
+        FragmentShader  GLSL300 GLSL150 GLSL100: Common/MatDefs/Terrain/SPTerrainLighting.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -184,6 +186,7 @@ MaterialDef Terrain Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             TRI_PLANAR_MAPPING : useTriPlanarMapping
             TERRAIN_GRID : isTerrainGrid
             WARDISO   : WardIso
@@ -236,8 +239,8 @@ MaterialDef Terrain Lighting {
 
     Technique PreShadow {
 
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Shadow/PreShadow.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Shadow/PreShadow.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PreShadow.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PreShadow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -245,6 +248,7 @@ MaterialDef Terrain Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             DIFFUSEMAP_ALPHA : DiffuseMap
         }
 
@@ -260,8 +264,8 @@ MaterialDef Terrain Lighting {
 
   Technique PreNormalPass {
 
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/SSAO/normal.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/SSAO/normal.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/SSAO/normal.vert
+        FragmentShader GLSL300 GLSL150 GLSL100:   Common/MatDefs/SSAO/normal.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -270,6 +274,7 @@ MaterialDef Terrain Lighting {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             DIFFUSEMAP_ALPHA : DiffuseMap
         }
 
@@ -283,14 +288,15 @@ MaterialDef Terrain Lighting {
 
     Technique Glow {
 
-        VertexShader GLSL100 GLSL150:   Common/MatDefs/Misc/Unshaded.vert
-        FragmentShader GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag
+        VertexShader    GLSL300 GLSL150 GLSL100:   Common/MatDefs/Misc/Unshaded.vert
+        FragmentShader  GLSL300 GLSL150 GLSL100: Common/MatDefs/Light/Glow.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HAS_GLOWMAP : GlowMap
             HAS_GLOWCOLOR : GlowColor
         }

+ 2 - 0
jme3-testdata/src/main/resources/Materials/Geom/SimpleGeom.geom

@@ -1,3 +1,5 @@
+#import "Common/ShaderLib/GLSLCompat.glsllib"
+
 layout (points) in;
 layout (line_strip) out;
 layout (max_vertices = 11) out;

+ 2 - 0
jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tsctrl

@@ -1,3 +1,5 @@
+#import "Common/ShaderLib/GLSLCompat.glsllib"
+
 layout(vertices=4) out;
 out gl_PerVertex{
   vec4 gl_Position;

+ 2 - 0
jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval

@@ -1,3 +1,5 @@
+#import "Common/ShaderLib/GLSLCompat.glsllib"
+
 layout (quads,equal_spacing,cw) in;
 
 uniform mat4 g_WorldViewProjectionMatrix;

+ 7 - 4
jme3-vr/src/main/resources/Common/MatDefs/VR/CartoonSSAO.j3md

@@ -1,6 +1,7 @@
 MaterialDef CartoonSSAO {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Int NumSamplesDepth
         Texture2D DepthTexture
@@ -14,8 +15,8 @@ MaterialDef CartoonSSAO {
     }
 
     Technique {
-            VertexShader GLSL150:   Common/MatDefs/Post/Post15.vert
-            FragmentShader GLSL150: Common/MatDefs/VR/CartoonSSAO.frag
+            VertexShader    GLSL300 GLSL150:   Common/MatDefs/Post/Post15.vert
+            FragmentShader  GLSL300 GLSL150: Common/MatDefs/VR/CartoonSSAO.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -24,14 +25,15 @@ MaterialDef CartoonSSAO {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             NO_OUTLINE : disableOutline
             INSTANCING : useInstancing
         }
     }
 
     Technique {
-            VertexShader GLSL100:   Common/MatDefs/Post/Post.vert
-            FragmentShader GLSL100: Common/MatDefs/VR/CartoonSSAO.frag
+            VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Post/Post.vert
+            FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/VR/CartoonSSAO.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -40,6 +42,7 @@ MaterialDef CartoonSSAO {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             NO_OUTLINE : disableOutline
             INSTANCING : useInstancing
         }

+ 7 - 4
jme3-vr/src/main/resources/Common/MatDefs/VR/GuiOverlay.j3md

@@ -1,6 +1,7 @@
 MaterialDef GuiOverlay {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D ColorMap
 
         // For VR instancing
@@ -8,8 +9,8 @@ MaterialDef GuiOverlay {
     }
 
     Technique {
-        VertexShader GLSL150:   Common/MatDefs/VR/GuiOverlay15.vert
-        FragmentShader GLSL150: Common/MatDefs/VR/GuiOverlay15.frag
+        VertexShader    GLSL300 GLSL150:   Common/MatDefs/VR/GuiOverlay15.vert
+        FragmentShader  GLSL300 GLSL150: Common/MatDefs/VR/GuiOverlay15.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -17,13 +18,14 @@ MaterialDef GuiOverlay {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             INSTANCING : RightEyeViewProjectionMatrix // For VR instancing
         }
     }
 
     Technique {
-        VertexShader GLSL100:   Common/MatDefs/VR/GuiOverlay.vert
-        FragmentShader GLSL100: Common/MatDefs/VR/GuiOverlay.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/VR/GuiOverlay.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/VR/GuiOverlay.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -31,6 +33,7 @@ MaterialDef GuiOverlay {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             INSTANCING : RightEyeViewProjectionMatrix // For VR instancing
         }
     }

+ 9 - 6
jme3-vr/src/main/resources/Common/MatDefs/VR/OpenVR.j3md

@@ -1,5 +1,6 @@
 MaterialDef OpenVR {
     MaterialParameters {
+        Int BoundDrawBuffer
         Int NumSamples
         Texture2D Texture
     
@@ -9,25 +10,27 @@ MaterialDef OpenVR {
     }
  
      Technique {
-        VertexShader GLSL150:   Common/MatDefs/VR/OpenVR15.vert
-        FragmentShader GLSL150: Common/MatDefs/VR/OpenVR15.frag
+        VertexShader   GLSL300 GLSL150:   Common/MatDefs/VR/OpenVR15.vert
+        FragmentShader GLSL300 GLSL150: Common/MatDefs/VR/OpenVR15.frag
  
         WorldParameters {
         }
  
         Defines {
-        }
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+         }
  
     }
  
     Technique {
-        VertexShader GLSL100:   Common/MatDefs/VR/OpenVR.vert
-        FragmentShader GLSL100: Common/MatDefs/VR/OpenVR.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/VR/OpenVR.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/VR/OpenVR.frag
  
         WorldParameters {
         }
  
         Defines {
-        } 
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
+         } 
     }
 }

+ 7 - 4
jme3-vr/src/main/resources/Common/MatDefs/VR/PostShadowFilter.j3md

@@ -1,6 +1,7 @@
 MaterialDef Post Shadow {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Int FilterMode
         Boolean HardwareShadows
 
@@ -46,14 +47,15 @@ MaterialDef Post Shadow {
     }
 
     Technique {
-        VertexShader GLSL150:   Common/MatDefs/VR/PostShadowFilter.vert
-        FragmentShader GLSL150: Common/MatDefs/VR/PostShadowFilter.frag
+        VertexShader     GLSL300 GLSL150:   Common/MatDefs/VR/PostShadowFilter.vert
+        FragmentShader   GLSL300 GLSL150: Common/MatDefs/VR/PostShadowFilter.frag
 
         WorldParameters {         
             ResolutionInverse
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             RESOLVE_MS : NumSamples
             RESOLVE_DEPTH_MS : NumSamplesDepth
             HARDWARE_SHADOWS : HardwareShadows
@@ -72,14 +74,15 @@ MaterialDef Post Shadow {
     }
 
     Technique {
-        VertexShader GLSL100:   Common/MatDefs/Shadow/PostShadowFilter.vert
-        FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadowFilter.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/Shadow/PostShadowFilter.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/Shadow/PostShadowFilter.frag
 
         WorldParameters {         
             ResolutionInverse
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             HARDWARE_SHADOWS : HardwareShadows
             FILTER_MODE : FilterMode
             PCFEDGE : PCFEdge

+ 7 - 4
jme3-vr/src/main/resources/Common/MatDefs/VR/Unshaded.j3md

@@ -1,6 +1,7 @@
 MaterialDef Unshaded {
 
     MaterialParameters {
+        Int BoundDrawBuffer
         Texture2D ColorMap
         Color Color (Color)
 
@@ -9,8 +10,8 @@ MaterialDef Unshaded {
     }
 
     Technique {
-        VertexShader GLSL150:   Common/MatDefs/VR/Unshaded.vert
-        FragmentShader GLSL150: Common/MatDefs/VR/Unshaded.frag
+        VertexShader    GLSL300 GLSL150:   Common/MatDefs/VR/Unshaded.vert
+        FragmentShader  GLSL300 GLSL150: Common/MatDefs/VR/Unshaded.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -19,6 +20,7 @@ MaterialDef Unshaded {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             INSTANCING : RightEyeViewProjectionMatrix // For VR instancing
             HAS_COLORMAP : ColorMap
             HAS_COLOR : Color
@@ -26,8 +28,8 @@ MaterialDef Unshaded {
     }
 
     Technique {
-        VertexShader GLSL100:   Common/MatDefs/VR/Unshaded.vert
-        FragmentShader GLSL100: Common/MatDefs/VR/Unshaded.frag
+        VertexShader   GLSL300 GLSL150 GLSL100:   Common/MatDefs/VR/Unshaded.vert
+        FragmentShader GLSL300 GLSL150 GLSL100: Common/MatDefs/VR/Unshaded.frag
 
         WorldParameters {
             WorldViewProjectionMatrix
@@ -36,6 +38,7 @@ MaterialDef Unshaded {
         }
 
         Defines {
+            BOUND_DRAW_BUFFER: BoundDrawBuffer
             INSTANCING : RightEyeViewProjectionMatrix // For VR instancing
             HAS_COLORMAP : ColorMap
             HAS_COLOR : Color