Android openGL ES 3 support (#1147)

* Update GLImageFormats.java

* Added basic support for openGL ES 3.0 and GLSL300 for android

Added instancing support for android which is core feature in GLES3.0

Added fix for shadows in android

* Fixed required types of GLES30.glDrawElementsInstanced

* Properly check GLES3 version and setting precision for shaders for all GLSL ES versions

* Added support for Opengl ES 3.1 and 3.2 and their shader versions
Added proper checkings for new OpenGL ES versions
Fixed some issues with shadow rendering in GLES 3.0 or better (strict type checking, OpenGL ES specific extensions and percision definition)
Added GLSL320 and GLSL300 to Unshaded and Lighting materials

* Added depth texture 24bit for OpenGL ES

* Added geometry shaders and tessellation to GLES 3.1 as extension and GLES 3.2 as core
Modified test materials to use GLSL310

* Added FB blit for android GLES30

* Added GlSL300 or better to all effects not able to run in GLSL100
Mods on Shadows.glsllib to try to fix android shadow rendering
Fixed ssaoBlur.frag that was using a reserved word
Fixed precision type missmatch from vertex to fragment shader

* Partial multisample support
Framebuffer MRT support

* Temporarily removed texture multisampling (not being able to compile using GLES31)

* Updated android.jar to api28
Enabled multisampling

* Better checking for GLES3

* Removed insert precision for all shaders. This avoided some random precision missmatch error but created rendering issues

* Removed border check for GLES, caused filtered shadows not to render on GLES2.0 devices

Added texture compare mode for GLES3.0 and better to be able to use sampler2DShadow

Modified base materials (Lighting and Unshaded) to use only GLSL100 for post shadow pass

* Corrected texture comparison function that were incorrectly changed

* Added precision to samplers for GLESSL300 also

* Created a subclass of Glsl150ShaderGenerator (Glsl300ShaderGenerator) to support ShaderNodes in GLES SL30 and included it's usage in DesktopAssetManager. Nowadays just copied and overwrote the version string. Needs a full review
Added image format RGB16F to be used as texture format only in GLES30 (cannot be used as FB format)
Added GLSL300 and/or GLSL310 to different materials

* Cleaned GLSL300 generator
Fixed shadows glsl lib removing use of GL_EXT_gpu_shaders5

* Fixed usag of textureCubeLod in fragment shader of envMapping which is unsupported in GLES2.0
Modified PBRLighting frag to properly compile on GLES3

* Added GLSL300 and 310 to PostShadowFilter material definition

* Make post shadow filter use GLSL100 for GLSL300
Set highp as default precision to fix glitched shadows caused because not enough precision

* Changed water_normalmap.dds to uncompressed RGB8 because DXT1 is mostly unsupported in GLES

* Fixed GLES30 compilation issues in Water shaders and added GLSL300 to LightScattering material. ** Not fully tested

* Added RGB8 dds formatted FullskiesSunset to be used in any platform. Previous file moved to _dtx1.dds

* Set GL_TEXTURE_MAX_LEVEL in GLES30 contexts fixing issue with not fully mipmapped images and PBR rendering

* Fixed compilation of jme3-android-examples and upgraded sdk version to use

* Fixed Geometry Shader and Tessellation Shaders in testdata package to properly compile on GLES320

* Added non-compressed textures to be able to run all examples on android

Enabled texture arrays and 3d textures on opengl es 3.0. Peding to implement wrappers to android gl functions (currently getting NullPointerException)

* More GLES30 functions included to properly support texture arrays, 3d textures and multisampling matching jme core code

* Fixed 3D texture tests for GLES30
Fixed texture 3D and texture array example shader compilation on GLES30
Fixed some random missing precision compilation errors on GLES30

* Fixed TestTextureArray for GLES30

* Some multisample additions and removal of GLES3 multisampling enable caps
Added RGBA16F as valid format for GLES32 and using it by default in env camera instead of RGB16F. kept fall back to RGB8

* added float and half float formats for gles30
added rgb10a2 format for gles30
fixed usage of glTexImage2D
removed EnvironmentCamera fallback image format as it's useless now

* Added more image formats for GLES30
Fixed rgb8 if having Caps.Rgba8

* Enabled RadialBlur for gles30

* Fixed luminance texture formats for gles

* Added more depth image formats for gles3

* Enabled multisampling in gles3

* Added GLES30 functions to GLDebugES
Reverted TestTexture3D and TestTextureArray to use RGB8 format
Updated EnvMapping100.frag to use EXT_shader_texture_lod in gles sl 100 if available

* Removed all aditional not used compressed dds files
Removed also Pond and rock png files previously used in TestTextureArray

* Removed compressed water_normalmap_dxt1.dds

* Changed GLES_30 and AndroidGL implementing GL2 to avoid duplicated code checking GL2 vs GLES30

* Added aditional checking to avoid gles30 calls from gles20 only devices
fix-openal-soft-deadlink
joliver82 5 years ago committed by Ali-RS
parent 7ae1ff23af
commit 663c9776e8
  1. 7
      build.gradle
  2. 13
      jme3-android-examples/build.gradle
  3. 10
      jme3-android-examples/src/main/java/org/jmonkeyengine/jme3androidexamples/JmeFragment.java
  4. 68
      jme3-android/src/main/java/com/jme3/renderer/android/AndroidGL.java
  5. 20
      jme3-android/src/main/java/com/jme3/system/android/AndroidConfigChooser.java
  6. 12
      jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java
  7. 5
      jme3-core/src/main/java/com/jme3/asset/DesktopAssetManager.java
  8. 40
      jme3-core/src/main/java/com/jme3/renderer/Caps.java
  9. 52
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLDebugES.java
  10. 46
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLES_30.java
  11. 24
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java
  12. 113
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
  13. 64
      jme3-core/src/main/java/com/jme3/shader/Glsl300ShaderGenerator.java
  14. 5
      jme3-core/src/main/java/com/jme3/texture/Image.java
  15. 4
      jme3-core/src/main/java/com/jme3/texture/image/ImageCodec.java
  16. 4
      jme3-core/src/main/resources/Common/MatDefs/Blur/RadialBlur.j3md
  17. 24
      jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md
  18. 2
      jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag
  19. 12
      jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md
  20. 20
      jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md
  21. 1
      jme3-core/src/main/resources/Common/MatDefs/ShaderNodes/Environment/envMapping.j3sn
  22. 9
      jme3-core/src/main/resources/Common/MatDefs/ShaderNodes/Environment/envMapping100.frag
  23. 4
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow.j3md
  24. 4
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadowFilter.j3md
  25. 9
      jme3-core/src/main/resources/Common/ShaderLib/GLSLCompat.glsllib
  26. 2
      jme3-core/src/main/resources/Common/ShaderLib/MultiSample.glsllib
  27. 29
      jme3-core/src/main/resources/Common/ShaderLib/Shadows.glsllib
  28. 4
      jme3-effects/src/main/resources/Common/MatDefs/Post/FXAA.j3md
  29. 4
      jme3-effects/src/main/resources/Common/MatDefs/Post/LightScattering.j3md
  30. 4
      jme3-effects/src/main/resources/Common/MatDefs/SSAO/ssao.j3md
  31. 72
      jme3-effects/src/main/resources/Common/MatDefs/SSAO/ssaoBlur.frag
  32. 4
      jme3-effects/src/main/resources/Common/MatDefs/SSAO/ssaoBlur.j3md
  33. BIN
      jme3-effects/src/main/resources/Common/MatDefs/Water/Textures/water_normalmap.dds
  34. 27
      jme3-effects/src/main/resources/Common/MatDefs/Water/Water.frag
  35. 4
      jme3-effects/src/main/resources/Common/MatDefs/Water/Water.j3md
  36. 4
      jme3-examples/src/main/java/jme3test/texture/TestTextureArrayCompressed.java
  37. 4
      jme3-examples/src/main/resources/jme3test/texture/UnshadedArray.frag
  38. 12
      jme3-examples/src/main/resources/jme3test/texture/UnshadedArray.j3md
  39. 2
      jme3-examples/src/main/resources/jme3test/texture/UnshadedArray.vert
  40. 2
      jme3-examples/src/main/resources/jme3test/texture/tex3D.frag
  41. 4
      jme3-examples/src/main/resources/jme3test/texture/tex3D.j3md
  42. 2
      jme3-examples/src/main/resources/jme3test/texture/tex3D.vert
  43. 2
      jme3-examples/src/main/resources/jme3test/texture/tex3DThumb.frag
  44. 4
      jme3-examples/src/main/resources/jme3test/texture/tex3DThumb.j3md
  45. 2
      jme3-examples/src/main/resources/jme3test/texture/tex3DThumb.vert
  46. 2
      jme3-testdata/src/main/resources/Materials/Geom/SimpleGeom.frag
  47. 4
      jme3-testdata/src/main/resources/Materials/Geom/SimpleGeom.geom
  48. 6
      jme3-testdata/src/main/resources/Materials/Geom/SimpleGeom.j3md
  49. 2
      jme3-testdata/src/main/resources/Materials/Geom/SimpleGeom.vert
  50. 2
      jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.frag
  51. 8
      jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.j3md
  52. 14
      jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tsctrl
  53. 2
      jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval
  54. 2
      jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.vert
  55. BIN
      jme3-testdata/src/main/resources/Scenes/Beach/FullskiesSunset0068.dds
  56. BIN
      jme3-testdata/src/main/resources/Textures/3D/flame.dds
  57. BIN
      jme3-testdata/src/main/resources/Textures/Sky/Bright/BrightSky.dds
  58. BIN
      jme3-testdata/src/main/resources/Textures/Sky/Bright/FullskiesBlueClear03.dds
  59. BIN
      jme3-testdata/src/main/resources/Textures/Terrain/BrickWall/BrickWall.dds
  60. BIN
      jme3-testdata/src/main/resources/Textures/Terrain/BrickWall/BrickWall_dxt5.dds
  61. BIN
      jme3-testdata/src/main/resources/Textures/Terrain/BrickWall/BrickWall_normal_parallax.dds
  62. BIN
      jme3-testdata/src/main/resources/Textures/Terrain/Pond/Pond.dds
  63. BIN
      jme3-testdata/src/main/resources/Textures/Terrain/Pond/Pond_dxt5.dds
  64. BIN
      lib/android.jar

@ -12,6 +12,13 @@ buildscript {
} }
} }
allprojects {
repositories {
google()
jcenter()
}
}
apply plugin: 'base' apply plugin: 'base'
apply from: file('version.gradle') apply from: file('version.gradle')

@ -1,8 +1,8 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 23 compileSdkVersion 28
buildToolsVersion "23.0.3" buildToolsVersion "28.0.3"
lintOptions { lintOptions {
// Fix nifty gui referencing "java.awt" package. // Fix nifty gui referencing "java.awt" package.
@ -13,7 +13,7 @@ android {
defaultConfig { defaultConfig {
applicationId "org.jmonkeyengine.jme3androidexamples" applicationId "org.jmonkeyengine.jme3androidexamples"
minSdkVersion 15 // Android 4.0.3 ICE CREAM SANDWICH minSdkVersion 15 // Android 4.0.3 ICE CREAM SANDWICH
targetSdkVersion 22 // Android 5.1 LOLLIPOP targetSdkVersion 28 // Android 9 PIE
versionCode 1 versionCode 1
versionName "1.0" // TODO: from settings.gradle versionName "1.0" // TODO: from settings.gradle
} }
@ -25,6 +25,11 @@ android {
} }
} }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets { sourceSets {
main { main {
java { java {
@ -42,7 +47,7 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:appcompat-v7:28.0.0'
compile project(':jme3-core') compile project(':jme3-core')
compile project(':jme3-android') compile project(':jme3-android')

@ -62,15 +62,15 @@ public class JmeFragment extends AndroidHarnessFragment {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
Bundle bundle=getArguments(); Bundle bundle=getArguments();
appClass = bundle.getString(SELECTED_APP_CLASS); appClass = bundle.getString(MainActivity.SELECTED_APP_CLASS);
// Log.d(this.getClass().getSimpleName(), "AppClass: " + appClass); // Log.d(this.getClass().getSimpleName(), "AppClass: " + appClass);
joystickEventsEnabled = bundle.getBoolean(ENABLE_JOYSTICK_EVENTS); joystickEventsEnabled = bundle.getBoolean(MainActivity.ENABLE_JOYSTICK_EVENTS);
// Log.d(this.getClass().getSimpleName(), "JoystickEventsEnabled: " + joystickEventsEnabled); // Log.d(this.getClass().getSimpleName(), "JoystickEventsEnabled: " + joystickEventsEnabled);
keyEventsEnabled = bundle.getBoolean(ENABLE_KEY_EVENTS); keyEventsEnabled = bundle.getBoolean(MainActivity.ENABLE_KEY_EVENTS);
// Log.d(this.getClass().getSimpleName(), "KeyEventsEnabled: " + keyEventsEnabled); // Log.d(this.getClass().getSimpleName(), "KeyEventsEnabled: " + keyEventsEnabled);
mouseEventsEnabled = bundle.getBoolean(ENABLE_MOUSE_EVENTS); mouseEventsEnabled = bundle.getBoolean(MainActivity.ENABLE_MOUSE_EVENTS);
// Log.d(this.getClass().getSimpleName(), "MouseEventsEnabled: " + mouseEventsEnabled); // Log.d(this.getClass().getSimpleName(), "MouseEventsEnabled: " + mouseEventsEnabled);
boolean verboseLogging = bundle.getBoolean(VERBOSE_LOGGING); boolean verboseLogging = bundle.getBoolean(MainActivity.VERBOSE_LOGGING);
// Log.d(this.getClass().getSimpleName(), "VerboseLogging: " + verboseLogging); // Log.d(this.getClass().getSimpleName(), "VerboseLogging: " + verboseLogging);
if (verboseLogging) { if (verboseLogging) {
// Set the default logging level (default=Level.INFO, Level.ALL=All Debug Info) // Set the default logging level (default=Level.INFO, Level.ALL=All Debug Info)

@ -34,6 +34,7 @@ package com.jme3.renderer.android;
import android.opengl.*; import android.opengl.*;
import com.jme3.renderer.RendererException; import com.jme3.renderer.RendererException;
import com.jme3.renderer.opengl.*; import com.jme3.renderer.opengl.*;
import com.jme3.util.BufferUtils;
import java.nio.Buffer; import java.nio.Buffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -41,7 +42,9 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
public class AndroidGL implements GL, GLExt, GLFbo { public class AndroidGL implements GL, GL2, GLES_30, GLExt, GLFbo {
IntBuffer tmpBuff = BufferUtils.createIntBuffer(1);
public void resetStats() { public void resetStats() {
} }
@ -361,7 +364,7 @@ public class AndroidGL implements GL, GLExt, GLFbo {
} }
public void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, ByteBuffer data) { public void glTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, ByteBuffer data) {
GLES20.glTexImage2D(target, level, format, width, height, 0, format, type, data); GLES20.glTexImage2D(target, level, internalFormat, width, height, 0, format, type, data);
} }
public void glTexParameterf(int target, int pname, float param) { public void glTexParameterf(int target, int pname, float param) {
@ -449,7 +452,7 @@ public class AndroidGL implements GL, GLExt, GLFbo {
} }
public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) { public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) {
throw new UnsupportedOperationException("FBO blit not available on Android"); GLES30.glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
} }
public void glBufferData(int target, IntBuffer data, int usage) { public void glBufferData(int target, IntBuffer data, int usage) {
@ -461,31 +464,31 @@ public class AndroidGL implements GL, GLExt, GLFbo {
} }
public void glDrawArraysInstancedARB(int mode, int first, int count, int primcount) { public void glDrawArraysInstancedARB(int mode, int first, int count, int primcount) {
throw new UnsupportedOperationException("Instancing not available on Android"); GLES30.glDrawArraysInstanced(mode, first, count, primcount);
} }
public void glDrawBuffers(IntBuffer bufs) { public void glDrawBuffers(IntBuffer bufs) {
throw new UnsupportedOperationException("MRT not available on Android"); GLES30.glDrawBuffers(bufs.limit(), bufs);
} }
public void glDrawElementsInstancedARB(int mode, int indices_count, int type, long indices_buffer_offset, int primcount) { public void glDrawElementsInstancedARB(int mode, int indices_count, int type, long indices_buffer_offset, int primcount) {
throw new UnsupportedOperationException("Instancing not available on Android"); GLES30.glDrawElementsInstanced(mode, indices_count, type, (int)indices_buffer_offset, primcount);
} }
public void glGetMultisample(int pname, int index, FloatBuffer val) { public void glGetMultisample(int pname, int index, FloatBuffer val) {
throw new UnsupportedOperationException("Multisample renderbuffers not available on Android"); GLES31.glGetMultisamplefv(pname, index, val);
} }
public void glRenderbufferStorageMultisampleEXT(int target, int samples, int internalformat, int width, int height) { public void glRenderbufferStorageMultisampleEXT(int target, int samples, int internalformat, int width, int height) {
throw new UnsupportedOperationException("Multisample renderbuffers not available on Android"); GLES30.glRenderbufferStorageMultisample(target, samples, internalformat, width, height);
} }
public void glTexImage2DMultisample(int target, int samples, int internalformat, int width, int height, boolean fixedsamplelocations) { public void glTexImage2DMultisample(int target, int samples, int internalformat, int width, int height, boolean fixedsamplelocations) {
throw new UnsupportedOperationException("Multisample textures not available on Android"); GLES31.glTexStorage2DMultisample(target, samples, internalformat, width, height, fixedsamplelocations);
} }
public void glVertexAttribDivisorARB(int index, int divisor) { public void glVertexAttribDivisorARB(int index, int divisor) {
throw new UnsupportedOperationException("Instancing not available on Android"); GLES30.glVertexAttribDivisor(index, divisor);
} }
public void glBindFramebufferEXT(int param1, int param2) { public void glBindFramebufferEXT(int param1, int param2) {
@ -564,6 +567,49 @@ public class AndroidGL implements GL, GLExt, GLFbo {
@Override @Override
public void glFramebufferTextureLayerEXT(int target, int attachment, int texture, int level, int layer) { public void glFramebufferTextureLayerEXT(int target, int attachment, int texture, int level, int layer) {
throw new UnsupportedOperationException("OpenGL ES 2 does not support texture arrays"); GLES30.glFramebufferTextureLayer(target, attachment, texture, level, layer);
}
public void glAlphaFunc(int func, float ref) {
} }
public void glPointSize(float size) {
}
public void glPolygonMode(int face, int mode) {
} }
// Wrapper to DrawBuffers as there's no DrawBuffer method in GLES
public void glDrawBuffer(int mode) {
tmpBuff.clear();
tmpBuff.put(0, mode);
tmpBuff.rewind();
glDrawBuffers(tmpBuff);
}
public void glReadBuffer(int mode) {
GLES30.glReadBuffer(mode);
}
public void glCompressedTexImage3D(int target, int level, int internalFormat, int width, int height, int depth,
int border, ByteBuffer data) {
GLES30.glCompressedTexImage3D(target, level, internalFormat, width, height, depth, border, getLimitBytes(data), data);
}
public void glCompressedTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width,
int height, int depth, int format, ByteBuffer data) {
GLES30.glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, getLimitBytes(data), data);
}
public void glTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, int border,
int format, int type, ByteBuffer data) {
GLES30.glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, data);
}
public void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height,
int depth, int format, int type, ByteBuffer data) {
GLES30.glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
}
}

@ -19,6 +19,7 @@ public class AndroidConfigChooser implements EGLConfigChooser {
private static final Logger logger = Logger.getLogger(AndroidConfigChooser.class.getName()); private static final Logger logger = Logger.getLogger(AndroidConfigChooser.class.getName());
protected AppSettings settings; protected AppSettings settings;
private final static int EGL_OPENGL_ES2_BIT = 4; private final static int EGL_OPENGL_ES2_BIT = 4;
private final static int EGL_OPENGL_ES3_BIT = 0x40;
public AndroidConfigChooser(AppSettings settings) { public AndroidConfigChooser(AppSettings settings) {
this.settings = settings; this.settings = settings;
@ -140,13 +141,30 @@ public class AndroidConfigChooser implements EGLConfigChooser {
int[] num_config = new int[1]; int[] num_config = new int[1];
int[] configSpec = new int[]{ int[] configSpec = new int[]{
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL10.EGL_NONE}; EGL10.EGL_NONE};
boolean gles3=true;
// Try openGL ES 3
try {
if (!egl.eglChooseConfig(display, configSpec, null, 0, num_config)) {
RendererUtil.checkEGLError(egl);
gles3=false;
}
} catch (com.jme3.renderer.RendererException re) {
// it's just the device not supporting GLES3. Fallback to GLES2
gles3=false;
}
if(!gles3)
{
// Get back to openGL ES 2
configSpec[1]=EGL_OPENGL_ES2_BIT;
if (!egl.eglChooseConfig(display, configSpec, null, 0, num_config)) { if (!egl.eglChooseConfig(display, configSpec, null, 0, num_config)) {
RendererUtil.checkEGLError(egl); RendererUtil.checkEGLError(egl);
throw new AssertionError(); throw new AssertionError();
} }
}
int numConfigs = num_config[0]; int numConfigs = num_config[0];
EGLConfig[] configs = new EGLConfig[numConfigs]; EGLConfig[] configs = new EGLConfig[numConfigs];

@ -53,6 +53,7 @@ import com.jme3.input.dummy.DummyKeyInput;
import com.jme3.input.dummy.DummyMouseInput; import com.jme3.input.dummy.DummyMouseInput;
import com.jme3.renderer.android.AndroidGL; import com.jme3.renderer.android.AndroidGL;
import com.jme3.renderer.opengl.GL; import com.jme3.renderer.opengl.GL;
import com.jme3.renderer.opengl.GLES_30;
import com.jme3.renderer.opengl.GLDebugES; import com.jme3.renderer.opengl.GLDebugES;
import com.jme3.renderer.opengl.GLExt; import com.jme3.renderer.opengl.GLExt;
import com.jme3.renderer.opengl.GLFbo; import com.jme3.renderer.opengl.GLFbo;
@ -99,13 +100,13 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
* @return GLSurfaceView The newly created view * @return GLSurfaceView The newly created view
*/ */
public GLSurfaceView createView(Context context) { public GLSurfaceView createView(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
// NOTE: We assume all ICS devices have OpenGL ES 2.0. // NOTE: We assume all ICS devices have OpenGL ES 2.0.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// below 4.0, check OpenGL ES 2.0 support. // below 4.0, check OpenGL ES 2.0 support.
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
if (info.reqGlEsVersion < 0x20000) { if (info.reqGlEsVersion < 0x20000) {
throw new UnsupportedOperationException("OpenGL ES 2.0 is not supported on this device"); throw new UnsupportedOperationException("OpenGL ES 2.0 or better is not supported on this device");
} }
} else if (Build.VERSION.SDK_INT < 9){ } else if (Build.VERSION.SDK_INT < 9){
throw new UnsupportedOperationException("jME3 requires Android 2.3 or later"); throw new UnsupportedOperationException("jME3 requires Android 2.3 or later");
@ -126,7 +127,8 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
// setEGLContextClientVersion must be set before calling setRenderer // setEGLContextClientVersion must be set before calling setRenderer
// this means it cannot be set in AndroidConfigChooser (too late) // this means it cannot be set in AndroidConfigChooser (too late)
view.setEGLContextClientVersion(2); // use proper openGL ES version
view.setEGLContextClientVersion(info.reqGlEsVersion>>16);
view.setFocusableInTouchMode(true); view.setFocusableInTouchMode(true);
view.setFocusable(true); view.setFocusable(true);
@ -201,7 +203,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
gl = new GLDebugES((GL) gl, (GLExt) gl, (GLFbo) gl); gl = new GLDebugES((GL) gl, (GLExt) gl, (GLFbo) gl);
} }
if (settings.getBoolean("GraphicsTrace")) { if (settings.getBoolean("GraphicsTrace")) {
gl = GLTracer.createGlesTracer(gl, GL.class, GLFbo.class, GLExt.class); gl = GLTracer.createGlesTracer(gl, GL.class, GLES_30.class, GLFbo.class, GLExt.class);
} }
renderer = new GLRenderer((GL)gl, (GLExt)gl, (GLFbo)gl); renderer = new GLRenderer((GL)gl, (GLExt)gl, (GLFbo)gl);
renderer.initialize(); renderer.initialize();

@ -41,6 +41,7 @@ import com.jme3.renderer.Caps;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.shader.Glsl100ShaderGenerator; import com.jme3.shader.Glsl100ShaderGenerator;
import com.jme3.shader.Glsl150ShaderGenerator; import com.jme3.shader.Glsl150ShaderGenerator;
import com.jme3.shader.Glsl300ShaderGenerator;
import com.jme3.shader.ShaderGenerator; import com.jme3.shader.ShaderGenerator;
import com.jme3.system.JmeSystem; import com.jme3.system.JmeSystem;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
@ -434,7 +435,9 @@ public class DesktopAssetManager implements AssetManager {
@Override @Override
public ShaderGenerator getShaderGenerator(EnumSet<Caps> caps) { public ShaderGenerator getShaderGenerator(EnumSet<Caps> caps) {
if (shaderGenerator == null) { if (shaderGenerator == null) {
if(caps.contains(Caps.GLSL150)){ if(caps.contains(Caps.OpenGLES30) && caps.contains(Caps.GLSL300)){
shaderGenerator = new Glsl300ShaderGenerator(this);
}else if(caps.contains(Caps.GLSL150)) {
shaderGenerator = new Glsl150ShaderGenerator(this); shaderGenerator = new Glsl150ShaderGenerator(this);
}else{ }else{
shaderGenerator = new Glsl100ShaderGenerator(this); shaderGenerator = new Glsl100ShaderGenerator(this);

@ -403,7 +403,45 @@ public enum Caps {
/** /**
* Supporting working with ShaderStorageBufferObjects. * Supporting working with ShaderStorageBufferObjects.
*/ */
ShaderStorageBufferObject; ShaderStorageBufferObject,
/**
* Supports OpenGL ES 3.0
*/
OpenGLES30,
/**
* Supports GLSL 3.0
*/
GLSL300,
/**
* Supports OpenGL ES 3.1
*/
OpenGLES31,
/**
* Supports GLSL 3.1
*/
GLSL310,
/**
* Supports OpenGL ES 3.2
*/
OpenGLES32,
/**
* Supports GLSL 3.2
*/
GLSL320,
/**
* Explicit support of depth 24 textures
*/
Depth24;
/** /**
* Returns true if given the renderer capabilities, the texture * Returns true if given the renderer capabilities, the texture

@ -5,7 +5,7 @@ import java.nio.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
public class GLDebugES extends GLDebug implements GL, GLFbo, GLExt { public class GLDebugES extends GLDebug implements GL, GL2, GLES_30, GLFbo, GLExt {
private final GLFbo glfbo; private final GLFbo glfbo;
private final GLExt glext; private final GLExt glext;
@ -609,4 +609,54 @@ public class GLDebugES extends GLDebug implements GL, GLFbo, GLExt {
glfbo.glFramebufferTextureLayerEXT(param1, param2, param3, param4, param5); glfbo.glFramebufferTextureLayerEXT(param1, param2, param3, param4, param5);
checkError(); checkError();
} }
public void glAlphaFunc(int func, float ref) {
((GL2)gl).glAlphaFunc(func, ref);
checkError();
}
public void glPointSize(float size) {
((GL2)gl).glPointSize(size);
checkError();
}
public void glPolygonMode(int face, int mode) {
((GL2)gl).glPolygonMode(face, mode);
checkError();
}
public void glDrawBuffer(int mode) {
((GL2)gl).glDrawBuffer(mode);
checkError();
}
public void glReadBuffer(int mode) {
((GL2)gl).glReadBuffer(mode);
checkError();
}
public void glCompressedTexImage3D(int target, int level, int internalFormat, int width, int height, int depth,
int border, ByteBuffer data) {
((GL2)gl).glCompressedTexImage3D(target, level, internalFormat, width, height, depth, border, data);
checkError();
}
public void glCompressedTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width,
int height, int depth, int format, ByteBuffer data) {
((GL2)gl).glCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, data);
checkError();
}
public void glTexImage3D(int target, int level, int internalFormat, int width, int height, int depth, int border,
int format, int type, ByteBuffer data) {
((GL2)gl).glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, data);
checkError();
}
public void glTexSubImage3D(int target, int level, int xoffset, int yoffset, int zoffset, int width, int height,
int depth, int format, int type, ByteBuffer data) {
((GL2)gl).glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
checkError();
}
} }

@ -0,0 +1,46 @@
/*
* Copyright (c) 2009-2019 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.
*/
package com.jme3.renderer.opengl;
import java.nio.ByteBuffer;
/**
* GL functions and constants only available on vanilla OpenGL ES 3.0.
*
* @author Jesus Oliver
*/
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;
}

@ -166,7 +166,7 @@ public final class GLImageFormats {
format(formatToGL, Format.Luminance8, GLExt.GL_RGBA8, GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE); format(formatToGL, Format.Luminance8, GLExt.GL_RGBA8, GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Luminance8Alpha8, GLExt.GL_RGBA8, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE); format(formatToGL, Format.Luminance8Alpha8, GLExt.GL_RGBA8, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
} }
format(formatToGL, Format.RGB8, GLExt.GL_RGBA8, GL.GL_RGB, GL.GL_UNSIGNED_BYTE); format(formatToGL, Format.RGB8, GL2.GL_RGB8, GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.RGBA8, GLExt.GL_RGBA8, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE); format(formatToGL, Format.RGBA8, GLExt.GL_RGBA8, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
formatSwiz(formatToGL, Format.BGR8, GL2.GL_RGB8, GL2.GL_RGB, GL.GL_UNSIGNED_BYTE); formatSwiz(formatToGL, Format.BGR8, GL2.GL_RGB8, GL2.GL_RGB, GL.GL_UNSIGNED_BYTE);
@ -218,6 +218,26 @@ public final class GLImageFormats {
} }
} }
// Supported in GLES30 core
if (caps.contains(Caps.OpenGLES30)) {
format(formatToGL, Format.RGB10A2, GLES_30.GL_RGB10_A2, GL.GL_RGBA, GLES_30.GL_UNSIGNED_INT_2_10_10_10_REV);
format(formatToGL, Format.Alpha8, GL2.GL_ALPHA8, GL.GL_ALPHA, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Luminance8, GL.GL_LUMINANCE, GL.GL_LUMINANCE, GL.GL_UNSIGNED_BYTE);
format(formatToGL, Format.Luminance8Alpha8, GL.GL_LUMINANCE_ALPHA, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
formatSrgb(formatToGL, Format.RGB8, GLExt.GL_SRGB8_EXT, GL.GL_RGB, GL.GL_UNSIGNED_BYTE);
formatSrgb(formatToGL, Format.RGBA8, GLExt.GL_SRGB8_ALPHA8_EXT, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
//Depending on the device could be better to use the previously defined extension based float textures instead of gles3.0 texture formats
// if (!caps.contains(Caps.FloatTexture)) {
format(formatToGL, Format.RGB16F, GLExt.GL_RGB16F_ARB, GL.GL_RGB, GLExt.GL_HALF_FLOAT_ARB);
format(formatToGL, Format.RGB32F, GLExt.GL_RGB32F_ARB, GL.GL_RGB, GL.GL_FLOAT);
format(formatToGL, Format.RGBA16F, GLExt.GL_RGBA16F_ARB, GL.GL_RGBA, GLExt.GL_HALF_FLOAT_ARB);
format(formatToGL, Format.RGBA32F, GLExt.GL_RGBA32F_ARB, GL.GL_RGBA, GL.GL_FLOAT);
// }
format(formatToGL, Format.RGB111110F, GLExt.GL_R11F_G11F_B10F_EXT, GL.GL_RGB, GLExt.GL_UNSIGNED_INT_10F_11F_11F_REV_EXT);
}
// Need to check if Caps.DepthTexture is supported prior to using for textures // Need to check if Caps.DepthTexture is supported prior to using for textures
// But for renderbuffers its OK. // But for renderbuffers its OK.
format(formatToGL, Format.Depth16, GL.GL_DEPTH_COMPONENT16, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_SHORT); format(formatToGL, Format.Depth16, GL.GL_DEPTH_COMPONENT16, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_SHORT);
@ -228,7 +248,7 @@ public final class GLImageFormats {
} else { } else {
format(formatToGL, Format.Depth, GL.GL_DEPTH_COMPONENT, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_BYTE); format(formatToGL, Format.Depth, GL.GL_DEPTH_COMPONENT, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_BYTE);
} }
if (caps.contains(Caps.OpenGL20)) { if (caps.contains(Caps.OpenGL20) || caps.contains(Caps.Depth24)) {
format(formatToGL, Format.Depth24, GL2.GL_DEPTH_COMPONENT24, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_INT); format(formatToGL, Format.Depth24, GL2.GL_DEPTH_COMPONENT24, GL.GL_DEPTH_COMPONENT, GL.GL_UNSIGNED_INT);
} }
if (caps.contains(Caps.FloatDepthBuffer)) { if (caps.contains(Caps.FloatDepthBuffer)) {

@ -71,6 +71,7 @@ import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public final class GLRenderer implements Renderer { public final class GLRenderer implements Renderer {
private static final Logger logger = Logger.getLogger(GLRenderer.class.getName()); private static final Logger logger = Logger.getLogger(GLRenderer.class.getName());
@ -166,9 +167,28 @@ public final class GLRenderer implements Renderer {
} }
private void loadCapabilitiesES() { private void loadCapabilitiesES() {
int oglVer = extractVersion(gl.glGetString(GL.GL_VERSION));
caps.add(Caps.GLSL100); caps.add(Caps.GLSL100);
caps.add(Caps.OpenGLES20); caps.add(Caps.OpenGLES20);
caps.add(Caps.Multisample);
if (oglVer >= 300) {
caps.add(Caps.OpenGLES30);
caps.add(Caps.GLSL300);
// Instancing is core in GLES300
caps.add(Caps.MeshInstancing);
}
if (oglVer >= 310) {
caps.add(Caps.OpenGLES31);
caps.add(Caps.GLSL310);
}
if (oglVer >= 320) {
caps.add(Caps.OpenGLES32);
caps.add(Caps.GLSL320);
caps.add(Caps.GeometryShader);
caps.add(Caps.TesselationShader);
}
// Important: Do not add OpenGL20 - that's the desktop capability! // Important: Do not add OpenGL20 - that's the desktop capability!
} }
@ -293,6 +313,7 @@ public final class GLRenderer implements Renderer {
if (hasExtension("GL_ARB_draw_instanced") && if (hasExtension("GL_ARB_draw_instanced") &&
hasExtension("GL_ARB_instanced_arrays")) { hasExtension("GL_ARB_instanced_arrays")) {
// TODO: If there were a way to call the EXT extension for GLES2, should check also (hasExtension("GL_EXT_draw_instanced") && hasExtension("GL_EXT_instanced_arrays"))
caps.add(Caps.MeshInstancing); caps.add(Caps.MeshInstancing);
} }
@ -330,8 +351,10 @@ public final class GLRenderer implements Renderer {
if (hasExtension("GL_OES_depth_texture") || gl2 != null) { if (hasExtension("GL_OES_depth_texture") || gl2 != null) {
caps.add(Caps.DepthTexture); caps.add(Caps.DepthTexture);
}
// TODO: GL_OES_depth24 if (hasExtension("GL_OES_depth24")) {
caps.add(Caps.Depth24);
} }
if (hasExtension("GL_OES_rgb8_rgba8") || if (hasExtension("GL_OES_rgb8_rgba8") ||
@ -340,7 +363,7 @@ public final class GLRenderer implements Renderer {
caps.add(Caps.Rgba8); caps.add(Caps.Rgba8);
} }
if (caps.contains(Caps.OpenGL30) || hasExtension("GL_OES_packed_depth_stencil")) { if (caps.contains(Caps.OpenGL30) || caps.contains(Caps.OpenGLES30) || hasExtension("GL_OES_packed_depth_stencil")) {
caps.add(Caps.PackedDepthStencilBuffer); caps.add(Caps.PackedDepthStencilBuffer);
} }
@ -350,7 +373,7 @@ public final class GLRenderer implements Renderer {
caps.add(Caps.FloatColorBuffer); caps.add(Caps.FloatColorBuffer);
} }
if (hasExtension("GL_ARB_depth_buffer_float")) { if (caps.contains(Caps.OpenGLES30) || hasExtension("GL_ARB_depth_buffer_float")) {
caps.add(Caps.FloatDepthBuffer); caps.add(Caps.FloatDepthBuffer);
} }
@ -397,7 +420,7 @@ public final class GLRenderer implements Renderer {
caps.add(Caps.PartialNonPowerOfTwoTextures); caps.add(Caps.PartialNonPowerOfTwoTextures);
} }
if (hasExtension("GL_EXT_texture_array") || caps.contains(Caps.OpenGL30)) { if (hasExtension("GL_EXT_texture_array") || caps.contains(Caps.OpenGL30) || caps.contains(Caps.OpenGLES30)) {
caps.add(Caps.TextureArray); caps.add(Caps.TextureArray);
} }
@ -414,16 +437,16 @@ public final class GLRenderer implements Renderer {
limits.put(Limits.RenderBufferSize, getInteger(GLFbo.GL_MAX_RENDERBUFFER_SIZE_EXT)); limits.put(Limits.RenderBufferSize, getInteger(GLFbo.GL_MAX_RENDERBUFFER_SIZE_EXT));
limits.put(Limits.FrameBufferAttachments, getInteger(GLFbo.GL_MAX_COLOR_ATTACHMENTS_EXT)); limits.put(Limits.FrameBufferAttachments, getInteger(GLFbo.GL_MAX_COLOR_ATTACHMENTS_EXT));
if (hasExtension("GL_EXT_framebuffer_blit") || caps.contains(Caps.OpenGL30)) { if (hasExtension("GL_EXT_framebuffer_blit") || caps.contains(Caps.OpenGL30) || caps.contains(Caps.OpenGLES30)) {
caps.add(Caps.FrameBufferBlit); caps.add(Caps.FrameBufferBlit);
} }
if (hasExtension("GL_EXT_framebuffer_multisample")) { if (hasExtension("GL_EXT_framebuffer_multisample") || caps.contains(Caps.OpenGLES30)) {
caps.add(Caps.FrameBufferMultisample); caps.add(Caps.FrameBufferMultisample);
limits.put(Limits.FrameBufferSamples, getInteger(GLExt.GL_MAX_SAMPLES_EXT)); limits.put(Limits.FrameBufferSamples, getInteger(GLExt.GL_MAX_SAMPLES_EXT));
} }
if (hasExtension("GL_ARB_texture_multisample")) { if (hasExtension("GL_ARB_texture_multisample") || caps.contains(Caps.OpenGLES31)) { // GLES31 does not fully support it
caps.add(Caps.TextureMultisample); caps.add(Caps.TextureMultisample);
limits.put(Limits.ColorTextureSamples, getInteger(GLExt.GL_MAX_COLOR_TEXTURE_SAMPLES)); limits.put(Limits.ColorTextureSamples, getInteger(GLExt.GL_MAX_COLOR_TEXTURE_SAMPLES));
limits.put(Limits.DepthTextureSamples, getInteger(GLExt.GL_MAX_DEPTH_TEXTURE_SAMPLES)); limits.put(Limits.DepthTextureSamples, getInteger(GLExt.GL_MAX_DEPTH_TEXTURE_SAMPLES));
@ -433,7 +456,7 @@ public final class GLRenderer implements Renderer {
} }
} }
if (hasExtension("GL_ARB_draw_buffers") || caps.contains(Caps.OpenGL30)) { if (hasExtension("GL_ARB_draw_buffers") || caps.contains(Caps.OpenGL30) || caps.contains(Caps.OpenGLES30)) {
limits.put(Limits.FrameBufferMrtAttachments, getInteger(GLExt.GL_MAX_DRAW_BUFFERS_ARB)); limits.put(Limits.FrameBufferMrtAttachments, getInteger(GLExt.GL_MAX_DRAW_BUFFERS_ARB));
if (limits.get(Limits.FrameBufferMrtAttachments) > 1) { if (limits.get(Limits.FrameBufferMrtAttachments) > 1) {
caps.add(Caps.FrameBufferMRT); caps.add(Caps.FrameBufferMRT);
@ -443,7 +466,7 @@ public final class GLRenderer implements Renderer {
} }
} }
if (hasExtension("GL_ARB_multisample")) { if (hasExtension("GL_ARB_multisample") /*|| caps.contains(Caps.OpenGLES20)*/) {
boolean available = getInteger(GLExt.GL_SAMPLE_BUFFERS_ARB) != 0; boolean available = getInteger(GLExt.GL_SAMPLE_BUFFERS_ARB) != 0;
int samples = getInteger(GLExt.GL_SAMPLES_ARB); int samples = getInteger(GLExt.GL_SAMPLES_ARB);
logger.log(Level.FINER, "Samples: {0}", samples); logger.log(Level.FINER, "Samples: {0}", samples);
@ -498,6 +521,14 @@ public final class GLRenderer implements Renderer {
limits.put(Limits.UniformBufferObjectMaxVertexBlocks, getInteger(GL3.GL_MAX_VERTEX_UNIFORM_BLOCKS)); limits.put(Limits.UniformBufferObjectMaxVertexBlocks, getInteger(GL3.GL_MAX_VERTEX_UNIFORM_BLOCKS));
} }
if (hasExtension("GL_OES_geometry_shader") || hasExtension("GL_EXT_geometry_shader")) {
caps.add(Caps.GeometryShader);
}
if (hasExtension("GL_OES_tessellation_shader") || hasExtension("GL_EXT_tessellation_shader")) {
caps.add(Caps.TesselationShader);
}
// Print context information // Print context information
logger.log(Level.INFO, "OpenGL Renderer Information\n" + logger.log(Level.INFO, "OpenGL Renderer Information\n" +
" * Vendor: {0}\n" + " * Vendor: {0}\n" +
@ -539,7 +570,7 @@ public final class GLRenderer implements Renderer {
} }
private void loadCapabilities() { private void loadCapabilities() {
if (gl2 != null) { if (gl2 != null && !(gl instanceof GLES_30)) {
loadCapabilitiesGL2(); loadCapabilitiesGL2();
} else { } else {
loadCapabilitiesES(); loadCapabilitiesES();
@ -1327,10 +1358,11 @@ public final class GLRenderer implements Renderer {
throw new RendererException("Cannot recompile shader source"); throw new RendererException("Cannot recompile shader source");
} }
boolean gles3 = caps.contains(Caps.OpenGLES30);
boolean gles2 = caps.contains(Caps.OpenGLES20); boolean gles2 = caps.contains(Caps.OpenGLES20);
String language = source.getLanguage(); String language = source.getLanguage();
if (gles2 && !language.equals("GLSL100")) { if (!gles3 && gles2 && !language.equals("GLSL100")) { //avoid this check for gles3
throw new RendererException("This shader cannot run in OpenGL ES 2. " throw new RendererException("This shader cannot run in OpenGL ES 2. "
+ "Only GLSL 1.00 shaders are supported."); + "Only GLSL 1.00 shaders are supported.");
} }
@ -1339,24 +1371,25 @@ public final class GLRenderer implements Renderer {
// Upload shader source. // Upload shader source.
// Merge the defines and source code. // Merge the defines and source code.
stringBuf.setLength(0); stringBuf.setLength(0);
if (language.startsWith("GLSL")) {
int version = Integer.parseInt(language.substring(4)); int version = Integer.parseInt(language.substring(4));
if (language.startsWith("GLSL")) {
if (version > 100) { if (version > 100) {
stringBuf.append("#version "); stringBuf.append("#version ");
stringBuf.append(language.substring(4)); stringBuf.append(language.substring(4));
if (version >= 150) { if (version >= 150) {
if(gles3) {
stringBuf.append(" es");
}
else {
stringBuf.append(" core"); stringBuf.append(" core");
} }
}
stringBuf.append("\n"); stringBuf.append("\n");
} else { } else {
if (gles2) { if (gles2 || gles3) {
// request GLSL ES (1.00) when compiling under GLES2. // request GLSL ES (1.00) when compiling under GLES2.
stringBuf.append("#version 100\n"); stringBuf.append("#version 100\n");
if (source.getType() == ShaderType.Fragment) {
// GLES2 requires precision qualifier.
insertPrecision = true;
}
} else { } else {
// version 100 does not exist in desktop GLSL. // version 100 does not exist in desktop GLSL.
// put version 110 in that case to enable strict checking // put version 110 in that case to enable strict checking
@ -1364,6 +1397,15 @@ public final class GLRenderer implements Renderer {
stringBuf.append("#version 110\n"); stringBuf.append("#version 110\n");
} }
} }
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) { if (linearizeSrgbImages) {
@ -1375,11 +1417,22 @@ public final class GLRenderer implements Renderer {
stringBuf.append(source.getSource()); stringBuf.append(source.getSource());
if(insertPrecision){ 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 dirrective therefore it must be placed after #extension tokens to avoid // precision token is not a preprocessor dirrective therefore it must be placed after #extension tokens to avoid
// Error P0001: Extension directive must occur before any non-preprocessor tokens // Error P0001: Extension directive must occur before any non-preprocessor tokens
int idx = stringBuf.lastIndexOf("#extension"); int idx = stringBuf.lastIndexOf("#extension");
idx = stringBuf.indexOf("\n", idx); idx = stringBuf.indexOf("\n", idx);
stringBuf.insert(idx + 1, "precision mediump float;\n");
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.clear();
@ -1612,6 +1665,7 @@ public final class GLRenderer implements Renderer {
if (copyDepth) { if (copyDepth) {
mask |= GL.GL_DEPTH_BUFFER_BIT; mask |= GL.GL_DEPTH_BUFFER_BIT;
} }
glfbo.glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, glfbo.glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1,
dstX0, dstY0, dstX1, dstY1, mask, dstX0, dstY0, dstX1, dstY1, mask,
GL.GL_NEAREST); GL.GL_NEAREST);
@ -1842,7 +1896,7 @@ public final class GLRenderer implements Renderer {
} }
public void setReadDrawBuffers(FrameBuffer fb) { public void setReadDrawBuffers(FrameBuffer fb) {
if (gl2 == null) { if (gl2 == null || gl instanceof GLES_30) {
return; return;
} }
@ -1982,6 +2036,7 @@ public final class GLRenderer implements Renderer {
context.boundReadBuf = rb.getSlot(); context.boundReadBuf = rb.getSlot();
} }
} }
} else { } else {
setFrameBuffer(null); setFrameBuffer(null);
} }
@ -2048,7 +2103,7 @@ public final class GLRenderer implements Renderer {
return GLExt.GL_TEXTURE_2D_ARRAY_EXT; return GLExt.GL_TEXTURE_2D_ARRAY_EXT;
} }
case ThreeDimensional: case ThreeDimensional:
if (!caps.contains(Caps.OpenGL20)) { if (!caps.contains(Caps.OpenGL20) && !caps.contains(Caps.OpenGLES30)) {
throw new RendererException("3D textures are not supported" + throw new RendererException("3D textures are not supported" +
" by the video hardware."); " by the video hardware.");
} }
@ -2172,9 +2227,9 @@ public final class GLRenderer implements Renderer {
switch (tex.getType()) { switch (tex.getType()) {
case ThreeDimensional: case ThreeDimensional:
case CubeMap: // cubemaps use 3D coords case CubeMap: // cubemaps use 3D coords
if (gl2 != null && curState.rWrap != tex.getWrap(WrapAxis.R)) { if (gl2 != null && (caps.contains(Caps.OpenGL20) || caps.contains(Caps.OpenGLES30)) && curState.rWrap != tex.getWrap(WrapAxis.R)) {
bindTextureAndUnit(target, image, unit); bindTextureAndUnit(target, image, unit);
gl2.glTexParameteri(target, GL2.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R))); gl.glTexParameteri(target, GL2.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
curState.rWrap = tex.getWrap(WrapAxis.R); curState.rWrap = tex.getWrap(WrapAxis.R);
} }
//There is no break statement on purpose here //There is no break statement on purpose here
@ -2196,17 +2251,17 @@ public final class GLRenderer implements Renderer {
} }
ShadowCompareMode texCompareMode = tex.getShadowCompareMode(); ShadowCompareMode texCompareMode = tex.getShadowCompareMode();
if (gl2 != null && curState.shadowCompareMode != texCompareMode) { if ( (gl2 != null || caps.contains(Caps.OpenGLES30)) && curState.shadowCompareMode != texCompareMode) {
bindTextureAndUnit(target, image, unit); bindTextureAndUnit(target, image, unit);
if (texCompareMode != ShadowCompareMode.Off) { if (texCompareMode != ShadowCompareMode.Off) {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_REF_TO_TEXTURE); gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_REF_TO_TEXTURE);
if (texCompareMode == ShadowCompareMode.GreaterOrEqual) { if (texCompareMode == ShadowCompareMode.GreaterOrEqual) {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL); gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
} else { } else {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL); gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
} }
} else { } else {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE); gl.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
} }
curState.shadowCompareMode = texCompareMode; curState.shadowCompareMode = texCompareMode;
} }
@ -2340,7 +2395,6 @@ public final class GLRenderer implements Renderer {
bindTextureAndUnit(target, img, unit); bindTextureAndUnit(target, img, unit);
int imageSamples = img.getMultiSamples(); int imageSamples = img.getMultiSamples();
if (imageSamples <= 1) { if (imageSamples <= 1) {
if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) { if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
// Image does not have mipmaps, but they are required. // Image does not have mipmaps, but they are required.
@ -2353,7 +2407,7 @@ public final class GLRenderer implements Renderer {
// For OpenGL3 and up. // For OpenGL3 and up.
// We'll generate mipmaps via glGenerateMipmapEXT (see below) // We'll generate mipmaps via glGenerateMipmapEXT (see below)
} }
} else if (caps.contains(Caps.OpenGL20)) { } else if (caps.contains(Caps.OpenGL20) || caps.contains(Caps.OpenGLES30)) {
if (img.hasMipmaps()) { if (img.hasMipmaps()) {
// Image already has mipmaps, set the max level based on the // Image already has mipmaps, set the max level based on the
// number of mipmaps we have. // number of mipmaps we have.
@ -3136,6 +3190,7 @@ public final class GLRenderer implements Renderer {
public boolean isTaskResultAvailable(int taskId) { public boolean isTaskResultAvailable(int taskId) {
return gl.glGetQueryObjectiv(taskId, GL.GL_QUERY_RESULT_AVAILABLE) == 1; return gl.glGetQueryObjectiv(taskId, GL.GL_QUERY_RESULT_AVAILABLE) == 1;
} }
@Override @Override
public boolean getAlphaToCoverage() { public boolean getAlphaToCoverage() {
if (caps.contains(Caps.Multisample)) { if (caps.contains(Caps.Multisample)) {

@ -0,0 +1,64 @@
/*
* Copyright (c) 2009-2012 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.
*/
package com.jme3.shader;
import com.jme3.asset.AssetManager;
import com.jme3.material.ShaderGenerationInfo;
import com.jme3.shader.Shader.ShaderType;
/**
* This shader Generator can generate Vertex and Fragment shaders from
* ShaderNodes for GLESSL 3.0
* Nowdays it's just a subclass of Glsl150ShaderGenerator overriding the version
* string because GLSL 1.5 is mostly compatible with GLESSL 3.0
*
* @author Nehon
* @author Joliver82
*/
public class Glsl300ShaderGenerator extends Glsl150ShaderGenerator {
/**
* Creates a Glsl300ShaderGenerator
*
* @param assetManager the assetmanager
*/
public Glsl300ShaderGenerator(AssetManager assetManager) {
super(assetManager);
}
@Override
protected String getLanguageAndVersion(ShaderType type) {
return "GLSL300";
}
}

@ -494,6 +494,11 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
* Requires {@link Caps#FloatTexture}. * Requires {@link Caps#FloatTexture}.
*/ */
RG32F(64,true), RG32F(64,true),
/**
* 10-bit red, green, and blue with 2-bit alpha.
*/
RGB10A2(32),
; ;
private int bpp; private int bpp;

@ -130,6 +130,10 @@ abstract class ImageCodec {
0, 11, 6, 1)); 0, 11, 6, 1));
((BitMaskImageCodec)params.get(Format.RGB5A1)).be = true; ((BitMaskImageCodec)params.get(Format.RGB5A1)).be = true;
params.put(Format.RGB10A2, new BitMaskImageCodec(4, 0,
2, 10, 10, 10,
0, 22, 12, 2));
// params.put(Format.RGBA8, new ByteAlignedImageCodec(4, 0, // params.put(Format.RGBA8, new ByteAlignedImageCodec(4, 0,
// 0, 1, 1, 1, // 0, 1, 1, 1,
// 0, 0, 1, 2)); // 0, 0, 1, 2));

@ -10,8 +10,8 @@ MaterialDef Radial Blur {
} }
Technique { Technique {
VertexShader GLSL120 GLSL150: Common/MatDefs/Post/Post.vert VertexShader GLSL300 GLSL120 GLSL150: Common/MatDefs/Post/Post.vert
FragmentShader GLSL120 GLSL150: Common/MatDefs/Blur/RadialBlur.frag FragmentShader GLSL300 GLSL120 GLSL150: Common/MatDefs/Blur/RadialBlur.frag
WorldParameters { WorldParameters {
} }

@ -133,8 +133,8 @@ MaterialDef Phong Lighting {
Technique { Technique {
LightMode SinglePass LightMode SinglePass
VertexShader GLSL100 GLSL150: Common/MatDefs/Light/SPLighting.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/SPLighting.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Light/SPLighting.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/SPLighting.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -180,8 +180,8 @@ MaterialDef Phong Lighting {
LightMode MultiPass LightMode MultiPass
VertexShader GLSL100 GLSL150: Common/MatDefs/Light/Lighting.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/Lighting.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Light/Lighting.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/Lighting.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -225,8 +225,8 @@ MaterialDef Phong Lighting {
Technique PreShadow { Technique PreShadow {
VertexShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.vert
FragmentShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -255,8 +255,8 @@ MaterialDef Phong Lighting {
Technique PostShadow { Technique PostShadow {
VertexShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -292,8 +292,8 @@ MaterialDef Phong Lighting {
Technique PreNormalPass { Technique PreNormalPass {
VertexShader GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.vert
FragmentShader GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -315,8 +315,8 @@ MaterialDef Phong Lighting {
Technique Glow { Technique Glow {
VertexShader GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix

@ -296,7 +296,7 @@ void main(){
weight3 /= weightSum; weight3 /= weightSum;
#endif #endif
#if USE_AMBIENT_LIGHT #ifdef USE_AMBIENT_LIGHT
color1.rgb *= g_AmbientLightColor.rgb; color1.rgb *= g_AmbientLightColor.rgb;
color2.rgb *= g_AmbientLightColor.rgb; color2.rgb *= g_AmbientLightColor.rgb;
color3.rgb *= g_AmbientLightColor.rgb; color3.rgb *= g_AmbientLightColor.rgb;

@ -123,8 +123,8 @@ MaterialDef PBR Lighting {
Technique { Technique {
LightMode SinglePassAndImageBased LightMode SinglePassAndImageBased
VertexShader GLSL110 GLSL150: Common/MatDefs/Light/PBRLighting.vert VertexShader GLSL300 GLSL110 GLSL150: Common/MatDefs/Light/PBRLighting.vert
FragmentShader GLSL110 GLSL150: Common/MatDefs/Light/PBRLighting.frag FragmentShader GLSL300 GLSL110 GLSL150: Common/MatDefs/Light/PBRLighting.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -167,8 +167,8 @@ MaterialDef PBR Lighting {
Technique PreShadow { Technique PreShadow {
VertexShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.vert VertexShader GLSL300 GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.vert
FragmentShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag FragmentShader GLSL300 GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -197,8 +197,8 @@ MaterialDef PBR Lighting {
Technique PostShadow{ Technique PostShadow{
VertexShader GLSL150: Common/MatDefs/Shadow/PostShadow.vert VertexShader GLSL310 GLSL300 GLSL150: Common/MatDefs/Shadow/PostShadow.vert
FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow.frag FragmentShader GLSL310 GLSL300 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix

@ -62,8 +62,8 @@ MaterialDef Unshaded {
} }
Technique { Technique {
VertexShader GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -88,8 +88,8 @@ MaterialDef Unshaded {
Technique PreNormalPass { Technique PreNormalPass {
VertexShader GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.vert
FragmentShader GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/SSAO/normal.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -109,8 +109,8 @@ MaterialDef Unshaded {
Technique PreShadow { Technique PreShadow {
VertexShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.vert
FragmentShader GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150 : Common/MatDefs/Shadow/PreShadow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -140,8 +140,8 @@ MaterialDef Unshaded {
Technique PostShadow { Technique PostShadow {
VertexShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -176,8 +176,8 @@ MaterialDef Unshaded {
Technique Glow { Technique Glow {
VertexShader GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Misc/Unshaded.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Light/Glow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix

@ -2,6 +2,7 @@ ShaderNodeDefinitions{
ShaderNodeDefinition EnvMapping { ShaderNodeDefinition EnvMapping {
Type: Fragment Type: Fragment
Shader GLSL300: Common/MatDefs/ShaderNodes/Environment/envMapping130.frag
Shader GLSL100: Common/MatDefs/ShaderNodes/Environment/envMapping100.frag Shader GLSL100: Common/MatDefs/ShaderNodes/Environment/envMapping100.frag
Shader GLSL130: Common/MatDefs/ShaderNodes/Environment/envMapping130.frag Shader GLSL130: Common/MatDefs/ShaderNodes/Environment/envMapping130.frag

@ -1,8 +1,17 @@
#extension GL_ARB_shader_texture_lod : enable #extension GL_ARB_shader_texture_lod : enable
#extension GL_EXT_shader_texture_lod : enable
void main(){ void main(){
//@input vec3 refVec the reflection vector //@input vec3 refVec the reflection vector
//@input samplerCube cubeMap the cube map //@input samplerCube cubeMap the cube map
//@output vec4 color the output color //@output vec4 color the output color
#ifdef GL_ES
#ifdef GL_EXT_shader_texture_lod
color = textureCubeLodEXT(cubeMap, refVec, 0.0);
#else
color = textureCube(cubeMap, refVec);
#endif
#else
color = textureCubeLod(cubeMap, refVec, 0.0); color = textureCubeLod(cubeMap, refVec, 0.0);
#endif
} }

@ -35,8 +35,8 @@ MaterialDef Post Shadow {
} }
Technique { Technique {
VertexShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.vert VertexShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag FragmentShader GLSL310 GLSL300 GLSL100 GLSL150: Common/MatDefs/Shadow/PostShadow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix

@ -42,8 +42,8 @@ MaterialDef Post Shadow {
} }
Technique { Technique {
VertexShader GLSL150: Common/MatDefs/Shadow/PostShadowFilter.vert VertexShader GLSL310 GLSL150: Common/MatDefs/Shadow/PostShadowFilter.vert
FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadowFilter15.frag FragmentShader GLSL310 GLSL150: Common/MatDefs/Shadow/PostShadowFilter15.frag
WorldParameters { WorldParameters {
ResolutionInverse ResolutionInverse

@ -19,13 +19,18 @@
#endif #endif
#if __VERSION__ >= 130 #if __VERSION__ >= 130
# ifdef GL_ES
out highp vec4 outFragColor;
# else
out vec4 outFragColor; out vec4 outFragColor;
#endif
# define texture1D texture # define texture1D texture
# define texture2D texture # define texture2D texture
# define texture3D texture # define texture3D texture
# define textureCube texture # define textureCube texture
# define texture2DLod textureLod # define texture2DLod textureLod
# define textureCubeLod textureLod # define textureCubeLod textureLod
# define texture2DArray texture
# if defined VERTEX_SHADER # if defined VERTEX_SHADER
# define varying out # define varying out
# define attribute in # define attribute in
@ -33,4 +38,8 @@ out vec4 outFragColor;
# define varying in # define varying in
# define gl_FragColor outFragColor # define gl_FragColor outFragColor
# endif # endif
#else
# define isnan(val) !(val<0.0||val>0.0||val==0.0)
#endif #endif

@ -16,7 +16,7 @@ uniform int m_NumSamplesDepth;
#endif #endif
// NOTE: Only define multisample functions if multisample is available // NOTE: Only define multisample functions if multisample is available
#if defined(GL_ARB_texture_multisample) #if defined(GL_ARB_texture_multisample) || (defined GL_ES && __VERSION__>=310)
vec4 textureFetch(in sampler2DMS tex,in vec2 texC, in int numSamples){ vec4 textureFetch(in sampler2DMS tex,in vec2 texC, in int numSamples){
ivec2 iTexC = ivec2(texC * vec2(textureSize(tex))); ivec2 iTexC = ivec2(texC * vec2(textureSize(tex)));
vec4 color = vec4(0.0); vec4 color = vec4(0.0);

@ -1,16 +1,23 @@
#if __VERSION__ >= 130 #if __VERSION__ >= 130
// Because gpu_shader5 is actually where those // Because gpu_shader5 is actually where those
// gather functions are declared to work on shadowmaps // gather functions are declared to work on shadowmaps
// This "if" statement is useless as jme3 changes line ordering, so all extensions are tried to be loaded
#ifdef GL_ES
#extension GL_OES_gpu_shader5 : enable
#else
#extension GL_ARB_gpu_shader5 : enable #extension GL_ARB_gpu_shader5 : enable
#endif
#define IVEC2 ivec2 #define IVEC2 ivec2
#if defined GL_ES #ifdef HARDWARE_SHADOWS
#define SHADOWMAP sampler2D
#define SHADOWCOMPARE(tex,coord) step(coord.z, texture2DProj(tex, coord).r)
#elif defined HARDWARE_SHADOWS
#define SHADOWMAP sampler2DShadow #define SHADOWMAP sampler2DShadow
#define SHADOWCOMPAREOFFSET(tex,coord,offset) textureProjOffset(tex, coord, offset) #define SHADOWCOMPAREOFFSET(tex,coord,offset) textureProjOffset(tex, coord, offset)
#define SHADOWCOMPARE(tex,coord) textureProj(tex, coord) #define SHADOWCOMPARE(tex,coord) textureProj(tex, coord)
#if defined GL_ES && __VERSION__ <= 300
#define SHADOWGATHER(tex,coord) step(coord.z, textureGather(tex, coord.xy))
#else
#define SHADOWGATHER(tex,coord) textureGather(tex, coord.xy, coord.z) #define SHADOWGATHER(tex,coord) textureGather(tex, coord.xy, coord.z)
#endif
#else #else
#define SHADOWMAP sampler2D #define SHADOWMAP sampler2D
#define SHADOWCOMPAREOFFSET(tex,coord,offset) step(coord.z, textureProjOffset(tex, coord, offset).r) #define SHADOWCOMPAREOFFSET(tex,coord,offset) step(coord.z, textureProjOffset(tex, coord, offset).r)
@ -31,7 +38,10 @@
#endif #endif
#else #else
#define IVEC2 vec2 #define IVEC2 vec2
#ifdef HARDWARE_SHADOWS #if defined GL_ES
#define SHADOWMAP sampler2D
#define SHADOWCOMPARE(tex,coord) step(coord.z, texture2DProj(tex, coord).r)
#elif defined HARDWARE_SHADOWS
#define SHADOWMAP sampler2DShadow #define SHADOWMAP sampler2DShadow
#define SHADOWCOMPARE(tex,coord) shadow2DProj(tex, coord).r #define SHADOWCOMPARE(tex,coord) shadow2DProj(tex, coord).r
#else #else
@ -91,10 +101,14 @@ float Shadow_DoShadowCompare(in SHADOWMAP tex,in vec4 projCoord){
} }
float Shadow_BorderCheck(in vec2 coord){ float Shadow_BorderCheck(in vec2 coord){
#ifdef GL_ES
return 0.0;
#else
// Fastest, "hack" method (uses 4-5 instructions) // Fastest, "hack" method (uses 4-5 instructions)
vec4 t = vec4(coord.xy, 0.0, 1.0); vec4 t = vec4(coord.xy, 0.0, 1.0);
t = step(t.wwxy, t.xyzz); t = step(t.wwxy, t.xyzz);
return dot(t,t); return dot(t,t);
#endif
} }
float Shadow_Nearest(in SHADOWMAP tex,in vec4 projCoord){ float Shadow_Nearest(in SHADOWMAP tex,in vec4 projCoord){
@ -117,7 +131,8 @@ float Shadow_DoDither_2x2(in SHADOWMAP tex, in vec4 projCoord){
return 1.0; return 1.0;
float shadow = 0.0; float shadow = 0.0;
IVEC2 o = IVEC2(mod(floor(gl_FragCoord.xy), 2.0)); //IVEC2 o = IVEC2(mod(floor(gl_FragCoord.xy), 2.0));
vec2 o = vec2(IVEC2(mod(floor(gl_FragCoord.xy), 2.0))); //Strict type checking in GLSL ES
shadow += Shadow_DoShadowCompareOffset(tex, projCoord, (vec2(-1.5, 1.5)+o)); shadow += Shadow_DoShadowCompareOffset(tex, projCoord, (vec2(-1.5, 1.5)+o));
shadow += Shadow_DoShadowCompareOffset(tex, projCoord, (vec2( 0.5, 1.5)+o)); shadow += Shadow_DoShadowCompareOffset(tex, projCoord, (vec2( 0.5, 1.5)+o));
shadow += Shadow_DoShadowCompareOffset(tex, projCoord, (vec2(-1.5, -0.5)+o)); shadow += Shadow_DoShadowCompareOffset(tex, projCoord, (vec2(-1.5, -0.5)+o));
@ -134,7 +149,7 @@ float Shadow_DoBilinear_2x2(in SHADOWMAP tex, in vec4 projCoord){
vec4 gather = vec4(0.0); vec4 gather = vec4(0.0);
#if __VERSION__ >= 130 #if __VERSION__ >= 130
#ifdef GL_ARB_gpu_shader5 #if defined GL_ARB_gpu_shader5 || defined GL_OES_gpu_shader5
vec4 coord = vec4(projCoord.xyz / projCoord.www,0.0); vec4 coord = vec4(projCoord.xyz / projCoord.www,0.0);
gather = SHADOWGATHER(tex, coord); gather = SHADOWGATHER(tex, coord);
#else #else

@ -8,8 +8,8 @@ MaterialDef FXAA {
Float ReduceMul Float ReduceMul
} }
Technique { Technique {
VertexShader GLSL100 GLSL150: Common/MatDefs/Post/FXAA.vert VertexShader GLSL300 GLSL100 GLSL150: Common/MatDefs/Post/FXAA.vert
FragmentShader GLSL100 GLSL150: Common/MatDefs/Post/FXAA.frag FragmentShader GLSL300 GLSL100 GLSL150: Common/MatDefs/Post/FXAA.frag
WorldParameters { WorldParameters {
ResolutionInverse ResolutionInverse
} }

@ -14,8 +14,8 @@ MaterialDef Light Scattering {
} }
Technique { Technique {
VertexShader GLSL150 GLSL120: Common/MatDefs/Post/Post.vert VertexShader GLSL300 GLSL150 GLSL120: Common/MatDefs/Post/Post.vert
FragmentShader GLSL150 GLSL120: Common/MatDefs/Post/LightScattering.frag FragmentShader GLSL300 GLSL150 GLSL120: Common/MatDefs/Post/LightScattering.frag
WorldParameters { WorldParameters {
} }

@ -18,8 +18,8 @@ MaterialDef SSAO {
} }
Technique { Technique {
VertexShader GLSL150 GLSL120: Common/MatDefs/Post/Post.vert VertexShader GLSL300 GLSL150 GLSL120: Common/MatDefs/Post/Post.vert
FragmentShader GLSL150 GLSL120: Common/MatDefs/SSAO/ssao.frag FragmentShader GLSL300 GLSL150 GLSL120: Common/MatDefs/SSAO/ssao.frag
WorldParameters { WorldParameters {
WorldViewMatrix WorldViewMatrix

@ -32,77 +32,77 @@ vec4 convolutionFilter(){
float zsum = 1.0; float zsum = 1.0;
float Zp =readDepth(texCoord); float Zp =readDepth(texCoord);
vec2 sample = vec2(x - 2.0 * xScale, y - 2.0 * yScale); vec2 samplePos = vec2(x - 2.0 * xScale, y - 2.0 * yScale);
float zTmp = readDepth(sample); float zTmp = readDepth(samplePos);
float coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); float coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x - 0.0 * xScale, y - 2.0 * yScale); samplePos = vec2(x - 0.0 * xScale, y - 2.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x + 2.0 * xScale, y - 2.0 * yScale); samplePos = vec2(x + 2.0 * xScale, y - 2.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x - 1.0 * xScale, y - 1.0 * yScale); samplePos = vec2(x - 1.0 * xScale, y - 1.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x + 1.0 * xScale, y - 1.0 * yScale); samplePos = vec2(x + 1.0 * xScale, y - 1.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x - 2.0 * xScale, y - 0.0 * yScale); samplePos = vec2(x - 2.0 * xScale, y - 0.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x + 2.0 * xScale, y - 0.0 * yScale); samplePos = vec2(x + 2.0 * xScale, y - 0.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x - 1.0 * xScale, y + 1.0 * yScale); samplePos = vec2(x - 1.0 * xScale, y + 1.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x + 1.0 * xScale, y + 1.0 * yScale); samplePos = vec2(x + 1.0 * xScale, y + 1.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x - 2.0 * xScale, y + 2.0 * yScale); samplePos = vec2(x - 2.0 * xScale, y + 2.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x - 0.0 * xScale, y + 2.0 * yScale); samplePos = vec2(x - 0.0 * xScale, y + 2.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
sample = vec2(x + 2.0 * xScale, y + 2.0 * yScale); samplePos = vec2(x + 2.0 * xScale, y + 2.0 * yScale);
zTmp =readDepth(sample); zTmp =readDepth(samplePos);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp)); coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
zsum += coefZ; zsum += coefZ;
sum += coefZ* texture2D( m_SSAOMap, sample); sum += coefZ* texture2D( m_SSAOMap, samplePos);
return sum / zsum; return sum / zsum;

@ -14,8 +14,8 @@ MaterialDef SSAOBlur {
} }
Technique { Technique {
VertexShader GLSL150 GLSL120: Common/MatDefs/Post/Post.vert VertexShader GLSL300 GLSL150 GLSL120: Common/MatDefs/Post/Post.vert
FragmentShader GLSL150 GLSL120: Common/MatDefs/SSAO/ssaoBlur.frag FragmentShader GLSL300 GLSL150 GLSL120: Common/MatDefs/SSAO/ssaoBlur.frag
WorldParameters { WorldParameters {
WorldViewMatrix WorldViewMatrix

@ -48,9 +48,8 @@ uniform vec3 m_Center;
uniform float m_Radius; uniform float m_Radius;
#endif #endif
vec2 scale; // = vec2(m_WaveScale, m_WaveScale);
vec2 scale = vec2(m_WaveScale, m_WaveScale); float refractionScale; // = m_WaveScale;
float refractionScale = m_WaveScale;
// Modifies 4 sampled normals. Increase first values to have more // Modifies 4 sampled normals. Increase first values to have more
// smaller "waves" or last to have more bigger "waves" // smaller "waves" or last to have more bigger "waves"
@ -62,8 +61,18 @@ const float visibility = 3.0;
// foam intensity // foam intensity
uniform float m_FoamIntensity ; uniform float m_FoamIntensity ;
vec2 m_FrustumNearFar; //=vec2(1.0,m_UnderWaterFogDistance);
const float LOG2 = 1.442695;
varying vec2 texCoord; varying vec2 texCoord;
void setGlobals(){
scale = vec2(m_WaveScale, m_WaveScale);
refractionScale = m_WaveScale;
m_FrustumNearFar=vec2(1.0,m_UnderWaterFogDistance);
}
mat3 MatrixInverse(in mat3 inMatrix){ mat3 MatrixInverse(in mat3 inMatrix){
float det = dot(cross(inMatrix[0], inMatrix[1]), inMatrix[2]); float det = dot(cross(inMatrix[0], inMatrix[1]), inMatrix[2]);
mat3 T = transpose(inMatrix); mat3 T = transpose(inMatrix);
@ -119,9 +128,6 @@ float fresnelTerm(in vec3 normal,in vec3 eyeVec){
return saturate(fresnel * (1.0 - saturate(m_R0)) + m_R0 - m_RefractionStrength); return saturate(fresnel * (1.0 - saturate(m_R0)) + m_R0 - m_RefractionStrength);
} }
vec2 m_FrustumNearFar=vec2(1.0,m_UnderWaterFogDistance);
const float LOG2 = 1.442695;
vec4 underWater(int sampleNum){ vec4 underWater(int sampleNum){
@ -225,7 +231,7 @@ vec4 underWater(int sampleNum){
#endif #endif
float fogDepth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - sceneDepth* (m_FrustumNearFar.y-m_FrustumNearFar.x)); float fogDepth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - sceneDepth* (m_FrustumNearFar.y-m_FrustumNearFar.x));
float fogIntensity= 18 * m_WaterTransparency; float fogIntensity= 18.0 * m_WaterTransparency;
fogFactor = exp2( -fogIntensity * fogIntensity * fogDepth * fogDepth * LOG2 ); fogFactor = exp2( -fogIntensity * fogIntensity * fogDepth * fogDepth * LOG2 );
fogFactor = clamp(fogFactor, 0.0, 1.0); fogFactor = clamp(fogFactor, 0.0, 1.0);
color =mix(m_DeepWaterColor.rgb,color,fogFactor); color =mix(m_DeepWaterColor.rgb,color,fogFactor);
@ -284,7 +290,7 @@ vec4 main_multiSample(int sampleNum){
samples = 10; samples = 10;
#endif #endif
float biasFactor = 1.0 / samples; float biasFactor = 1.0 / float(samples);
for (int i = 0; i < samples; i++){ for (int i = 0; i < samples; i++){
texC = (surfacePoint.xz + eyeVecNorm.xz * biasFactor) * scale + m_Time * 0.03 * m_WindDirection; texC = (surfacePoint.xz + eyeVecNorm.xz * biasFactor) * scale + m_Time * 0.03 * m_WindDirection;
@ -344,7 +350,7 @@ vec4 main_multiSample(int sampleNum){
normal = normalize(normal0a * normalModifier.x + normal1a * normalModifier.y +normal2a * normalModifier.z + normal3a * normalModifier.w); normal = normalize(normal0a * normalModifier.x + normal1a * normalModifier.y +normal2a * normalModifier.z + normal3a * normalModifier.w);
#if __VERSION__ >= 130 #if __VERSION__ >= 130 && !defined GL_ES
// XXX: Here's another way to fix the terrain edge issue, // XXX: Here's another way to fix the terrain edge issue,
// But it requires GLSL 1.3 and still looks kinda incorrect // But it requires GLSL 1.3 and still looks kinda incorrect
// around edges // around edges
@ -435,12 +441,13 @@ vec4 main_multiSample(int sampleNum){
} }
void main(){ void main(){
setGlobals();
#ifdef RESOLVE_MS #ifdef RESOLVE_MS
vec4 color = vec4(0.0); vec4 color = vec4(0.0);
for (int i = 0; i < m_NumSamples; i++){ for (int i = 0; i < m_NumSamples; i++){
color += main_multiSample(i); color += main_multiSample(i);
} }
gl_FragColor = color / m_NumSamples; gl_FragColor = color / float(m_NumSamples);
#else #else
gl_FragColor = main_multiSample(0); gl_FragColor = main_multiSample(0);
#endif #endif

@ -51,8 +51,8 @@ MaterialDef Advanced Water {
} }
Technique { Technique {
VertexShader GLSL150 GLSL120 : Common/MatDefs/Post/Post.vert VertexShader GLSL310 GLSL300 GLSL150 GLSL120 : Common/MatDefs/Post/Post.vert
FragmentShader GLSL150 GLSL120: Common/MatDefs/Water/Water.frag FragmentShader GLSL310 GLSL300 GLSL150 GLSL120: Common/MatDefs/Water/Water.frag
WorldParameters { WorldParameters {
ViewProjectionMatrixInverse ViewProjectionMatrixInverse

@ -31,8 +31,8 @@ public class TestTextureArrayCompressed extends SimpleApplication
} }
Texture tex1 = assetManager.loadTexture( "Textures/Terrain/Pond/Pond.dds"); Texture tex1 = assetManager.loadTexture( "Textures/Terrain/Pond/Pond_dxt5.dds");
Texture tex2 = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.dds"); Texture tex2 = assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall_dxt5.dds");
List<Image> images = new ArrayList<Image>(); List<Image> images = new ArrayList<Image>();
images.add(tex1.getImage()); images.add(tex1.getImage());
images.add(tex2.getImage()); images.add(tex2.getImage());

@ -1,3 +1,5 @@
#import "Common/ShaderLib/GLSLCompat.glsllib"
#extension GL_EXT_texture_array : enable #extension GL_EXT_texture_array : enable
// #extension GL_EXT_gpu_shader4 : enable // #extension GL_EXT_gpu_shader4 : enable
@ -8,7 +10,7 @@ uniform vec4 m_Color;
#endif #endif
#ifdef HAS_COLORMAP #ifdef HAS_COLORMAP
#if !defined(GL_EXT_texture_array) #if !defined(GL_EXT_texture_array) && __VERSION__ < 130
#error Texture arrays are not supported, but required for this shader. #error Texture arrays are not supported, but required for this shader.
#endif #endif

@ -14,8 +14,8 @@ MaterialDef Unshaded {
} }
Technique { Technique {
VertexShader GLSL100: jme3test/texture/UnshadedArray.vert VertexShader GLSL300 GLSL100: jme3test/texture/UnshadedArray.vert
FragmentShader GLSL100: jme3test/texture/UnshadedArray.frag FragmentShader GLSL300 GLSL100: jme3test/texture/UnshadedArray.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -32,8 +32,8 @@ MaterialDef Unshaded {
Technique PreNormalPass { Technique PreNormalPass {
VertexShader GLSL100 : Common/MatDefs/SSAO/normal.vert VertexShader GLSL300 GLSL100 : Common/MatDefs/SSAO/normal.vert
FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag FragmentShader GLSL300 GLSL100 : Common/MatDefs/SSAO/normal.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
@ -50,8 +50,8 @@ MaterialDef Unshaded {
Technique Glow { Technique Glow {
VertexShader GLSL100: Cjme3test/texture/UnshadedArray.vert VertexShader GLSL300 GLSL100: jme3test/texture/UnshadedArray.vert
FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag FragmentShader GLSL300 GLSL100: Common/MatDefs/Light/Glow.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix

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

@ -1,3 +1,5 @@
#import "Common/ShaderLib/GLSLCompat.glsllib"
uniform sampler3D m_Texture; uniform sampler3D m_Texture;
varying vec3 texCoord; varying vec3 texCoord;

@ -5,8 +5,8 @@ MaterialDef My MaterialDef {
} }
Technique { Technique {
VertexShader GLSL100: jme3test/texture/tex3D.vert VertexShader GLSL300 GLSL100: jme3test/texture/tex3D.vert
FragmentShader GLSL100: jme3test/texture/tex3D.frag FragmentShader GLSL300 GLSL100: jme3test/texture/tex3D.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix

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

@ -1,3 +1,5 @@
#import "Common/ShaderLib/GLSLCompat.glsllib"
uniform sampler3D m_Texture; uniform sampler3D m_Texture;
uniform int m_Rows; uniform int m_Rows;
uniform float m_InvDepth; uniform float m_InvDepth;

@ -7,8 +7,8 @@ MaterialDef Tex3DThumb {
} }
Technique { Technique {
VertexShader GLSL100: jme3test/texture/tex3DThumb.vert VertexShader GLSL300 GLSL100: jme3test/texture/tex3DThumb.vert
FragmentShader GLSL100: jme3test/texture/tex3DThumb.frag FragmentShader GLSL300 GLSL100: jme3test/texture/tex3DThumb.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix

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

@ -1,3 +1,5 @@
#import "Common/ShaderLib/GLSLCompat.glsllib"
void main(){ void main(){
gl_FragColor=vec4(1.0,0.0,1.0,0.5); gl_FragColor=vec4(1.0,0.0,1.0,0.5);
} }

@ -7,8 +7,8 @@ const float PI = 3.1415926;
void main(){ void main(){
for (int i = 0; i <= 10; i++) { for (int i = 0; i <= 10; i++) {
float ang = PI * 2.0 / 10.0 * i; float ang = PI * 2.0 / 10.0 * float(i);
vec4 offset = vec4(cos(ang) * 5, -sin(ang) * 5, 0.0, 0.0); vec4 offset = vec4(cos(ang) * 5.0, -sin(ang) * 5.0, 0.0, 0.0);
gl_Position = g_WorldViewProjectionMatrix*vec4(gl_in[0].gl_Position.xyz + offset.xyz,1.0); gl_Position = g_WorldViewProjectionMatrix*vec4(gl_in[0].gl_Position.xyz + offset.xyz,1.0);
EmitVertex(); EmitVertex();

@ -5,9 +5,9 @@ MaterialDef SimpleGeom {
} }
Technique { Technique {
VertexShader GLSL330: Materials/Geom/SimpleGeom.vert VertexShader GLSL330 GLSL320: Materials/Geom/SimpleGeom.vert
GeometryShader GLSL330: Materials/Geom/SimpleGeom.geom GeometryShader GLSL330 GLSL320: Materials/Geom/SimpleGeom.geom
FragmentShader GLSL330: Materials/Geom/SimpleGeom.frag FragmentShader GLSL330 GLSL320: Materials/Geom/SimpleGeom.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix

@ -1,3 +1,5 @@
#import "Common/ShaderLib/GLSLCompat.glsllib"
attribute vec3 inPosition; attribute vec3 inPosition;
void main(){ void main(){

@ -1,3 +1,5 @@
#import "Common/ShaderLib/GLSLCompat.glsllib"
void main(){ void main(){
gl_FragColor=vec4(1.0,0.0,1.0,0.5); gl_FragColor=vec4(1.0,0.0,1.0,0.5);
} }

@ -6,10 +6,10 @@ MaterialDef SimpleGeom {
} }
Technique { Technique {
VertexShader GLSL400: Materials/Tess/SimpleTess.vert VertexShader GLSL400 GLSL320: Materials/Tess/SimpleTess.vert
TessellationEvaluationShader GLSL400: Materials/Tess/SimpleTess.tseval TessellationEvaluationShader GLSL400 GLSL320: Materials/Tess/SimpleTess.tseval
TessellationControlShader GLSL400: Materials/Tess/SimpleTess.tsctrl TessellationControlShader GLSL400 GLSL320: Materials/Tess/SimpleTess.tsctrl
FragmentShader GLSL400: Materials/Tess/SimpleTess.frag FragmentShader GLSL400 GLSL320: Materials/Tess/SimpleTess.frag
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix

@ -5,13 +5,15 @@ out gl_PerVertex{
uniform int m_TessellationFactor; uniform int m_TessellationFactor;
void main(){ void main(){
if (gl_InvocationID == 0){ if (gl_InvocationID == 0){
gl_TessLevelOuter[0]=m_TessellationFactor; float f_TessellationFactor=float(m_TessellationFactor);
gl_TessLevelOuter[1]=m_TessellationFactor;
gl_TessLevelOuter[2]=m_TessellationFactor;
gl_TessLevelOuter[3]=m_TessellationFactor;
gl_TessLevelInner[0]=m_TessellationFactor; gl_TessLevelOuter[0]=f_TessellationFactor;
gl_TessLevelInner[1]=m_TessellationFactor; gl_TessLevelOuter[1]=f_TessellationFactor;
gl_TessLevelOuter[2]=f_TessellationFactor;
gl_TessLevelOuter[3]=f_TessellationFactor;
gl_TessLevelInner[0]=f_TessellationFactor;
gl_TessLevelInner[1]=f_TessellationFactor;
} }
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
} }

@ -8,6 +8,6 @@ void main(){
vec3 p1 = mix(gl_in[1].gl_Position.xyz, gl_in[2].gl_Position.xyz, gl_TessCoord.x); vec3 p1 = mix(gl_in[1].gl_Position.xyz, gl_in[2].gl_Position.xyz, gl_TessCoord.x);
// interpolate in vert direction // interpolate in vert direction
vec3 tePosition = mix(p0, p1, gl_TessCoord.y); vec3 tePosition = mix(p0, p1, gl_TessCoord.y);
gl_Position = g_WorldViewProjectionMatrix * vec4(tePosition, 1); gl_Position = g_WorldViewProjectionMatrix * vec4(tePosition, 1.0);
} }

@ -1,3 +1,5 @@
#import "Common/ShaderLib/GLSLCompat.glsllib"
attribute vec3 inPosition; attribute vec3 inPosition;
void main(){ void main(){

Binary file not shown.
Loading…
Cancel
Save