aboutsummaryrefslogtreecommitdiffstats
path: root/src/demos/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2019-06-23 08:03:04 +0200
committerSven Gothel <[email protected]>2019-06-23 08:03:04 +0200
commitbba73bc096250a3c7fc036d84b1ea054d1b70b06 (patch)
treeed02575eac2a46bd49627444dcce972946ae8d2e /src/demos/com/jogamp
parent154e91978498d8b6db9ce34a1f06b298bcf4c361 (diff)
iOS: Initial working commit supporting iOS (ipad pro 11)
using our OpenJFK 9 x86_64 and arm64 build. Test demo class is 'com.jogamp.opengl.demos.ios.Hello', residing in the new demo folder 'src/demos/com/jogamp/opengl/demos/ios/Hello.java'. This commit does not yet include a working NEWT specialization for iOS, but it shall followup soon. Instead this commit demonstrates JOGL operating on native UIWindow, UIView and CAEAGLLayer as provided by Nativewindow's IOSUtil. Test Video https://www.youtube.com/watch?v=Z4lUQNFTGMI +++ Notable bug: The FBO used and sharing the COLORBUFFER RENDERBUFFER memory resources with CAEAGLLayer to be displayed in the UIView seemingly cannot handle GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24 or GL_DEPTH_COMPONENT32 depth buffer - none at all (Device + Simulation). Therefor the default demo GLEventListener chosen here don't require a depth buffer ;-) This issue can hopefully be mitigated with other means than using a flat FBO sink similar to FBO multisampling.
Diffstat (limited to 'src/demos/com/jogamp')
-rw-r--r--src/demos/com/jogamp/opengl/demos/GearsObject.java336
-rw-r--r--src/demos/com/jogamp/opengl/demos/PointsDemo.java48
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/GearsES2.java673
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/GearsObjectES2.java146
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/LandscapeES2.java187
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/PointsDemoES2.java208
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/RedSquareES2.java274
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/PointsShader.fp53
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/PointsShader.vp53
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.fp16
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.java73
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.vp18
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader2.fp16
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/default.vp24
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/elektronenmultiplizierer_development.fp389
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/elektronenmultiplizierer_port.fp242
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-1.fp16
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-1.vp19
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-2.fp22
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-2.vp21
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/gears.fp48
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/gears.vp45
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/landscape.fp339
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/landscape.vp11
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/mgl_default_xxx.fp16
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/mgl_default_xxx.vp18
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/ruler.fp33
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/texsequence_xxx.fp30
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/texsequence_xxx.vp22
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/texture01_xxx.fp28
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/texture01_xxx.vp22
-rw-r--r--src/demos/com/jogamp/opengl/demos/es2/shader/texture02_xxx.fp28
-rw-r--r--src/demos/com/jogamp/opengl/demos/ios/Hello.java196
-rw-r--r--src/demos/com/jogamp/opengl/demos/ios/Hello0.java20
34 files changed, 3690 insertions, 0 deletions
diff --git a/src/demos/com/jogamp/opengl/demos/GearsObject.java b/src/demos/com/jogamp/opengl/demos/GearsObject.java
new file mode 100644
index 000000000..6ae4d87b4
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/GearsObject.java
@@ -0,0 +1,336 @@
+/**
+ * Copyright (C) 2011 JogAmp Community. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+package com.jogamp.opengl.demos;
+
+import java.nio.FloatBuffer;
+
+import com.jogamp.opengl.GL;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.util.GLArrayDataServer;
+
+/**
+ * GearsObject.java <BR>
+ * @author Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P>
+ */
+public abstract class GearsObject {
+ public static final FloatBuffer red = Buffers.newDirectFloatBuffer( new float[] { 0.8f, 0.1f, 0.0f, 0.7f } );
+ public static final FloatBuffer green = Buffers.newDirectFloatBuffer( new float[] { 0.0f, 0.8f, 0.2f, 0.7f } );
+ public static final FloatBuffer blue = Buffers.newDirectFloatBuffer( new float[] { 0.2f, 0.2f, 1.0f, 0.7f } );
+ public static final float M_PI = (float)Math.PI;
+
+ public final FloatBuffer gearColor;
+ public GLArrayDataServer frontFace;
+ public GLArrayDataServer frontSide;
+ public GLArrayDataServer backFace;
+ public GLArrayDataServer backSide;
+ public GLArrayDataServer outwardFace;
+ public GLArrayDataServer insideRadiusCyl;
+ public boolean isShared;
+ protected boolean validateBuffers = false;
+
+ public abstract GLArrayDataServer createInterleaved(boolean useMappedBuffers, int comps, int dataType, boolean normalized, int initialSize, int vboUsage);
+ public abstract void addInterleavedVertexAndNormalArrays(GLArrayDataServer array, int components);
+ public abstract void draw(GL gl, float x, float y, float angle);
+
+ private GLArrayDataServer createInterleavedClone(final GLArrayDataServer ads) {
+ final GLArrayDataServer n = new GLArrayDataServer(ads);
+ n.setInterleavedOffset(0);
+ return n;
+ }
+
+ private void init(final GL gl, final GLArrayDataServer array) {
+ array.enableBuffer(gl, true);
+ array.enableBuffer(gl, false);
+ }
+
+ public void destroy(final GL gl) {
+ if(!isShared) {
+ // could be already destroyed by shared configuration
+ if(null != frontFace) {
+ frontFace.destroy(gl);
+ }
+ if(null != frontSide) {
+ frontSide.destroy(gl);
+ }
+ if(null != backFace) {
+ backFace.destroy(gl);
+ }
+ if(null != backSide) {
+ backSide.destroy(gl);
+ }
+ if(null != outwardFace) {
+ outwardFace.destroy(gl);
+ }
+ if(null != insideRadiusCyl) {
+ insideRadiusCyl.destroy(gl);
+ }
+ }
+ frontFace=null;
+ frontSide=null;
+ backFace=null;
+ backSide=null;
+ outwardFace=null;
+ insideRadiusCyl=null;
+ isShared = false;
+ }
+
+ public GearsObject ( final GearsObject shared ) {
+ isShared = true;
+ validateBuffers = shared.validateBuffers;
+ frontFace = createInterleavedClone(shared.frontFace);
+ addInterleavedVertexAndNormalArrays(frontFace, 3);
+ backFace = createInterleavedClone(shared.backFace);
+ addInterleavedVertexAndNormalArrays(backFace, 3);
+ frontSide = createInterleavedClone(shared.frontSide);
+ addInterleavedVertexAndNormalArrays(frontSide, 3);
+ backSide= createInterleavedClone(shared.backSide);
+ addInterleavedVertexAndNormalArrays(backSide, 3);
+ outwardFace = createInterleavedClone(shared.outwardFace);
+ addInterleavedVertexAndNormalArrays(outwardFace, 3);
+ insideRadiusCyl = createInterleavedClone(shared.insideRadiusCyl);
+ addInterleavedVertexAndNormalArrays(insideRadiusCyl, 3);
+ gearColor = shared.gearColor;
+ }
+
+ public GearsObject (
+ final GL gl,
+ final boolean useMappedBuffers,
+ final FloatBuffer gearColor,
+ final float inner_radius,
+ final float outer_radius,
+ final float width, final int teeth, final float tooth_depth, final boolean validateBuffers)
+ {
+ final float dz = width * 0.5f;
+ int i;
+ float r0, r1, r2;
+ float angle, da;
+ float u, v, len;
+ final float s[] = new float[5];
+ final float c[] = new float[5];
+ final float normal[] = new float[3];
+ // final int tris_per_tooth = 32;
+
+ this.validateBuffers = validateBuffers;
+ this.isShared = false;
+ this.gearColor = gearColor;
+
+ r0 = inner_radius;
+ r1 = outer_radius - tooth_depth / 2.0f;
+ r2 = outer_radius + tooth_depth / 2.0f;
+
+ da = 2.0f * (float) Math.PI / teeth / 4.0f;
+
+ s[4] = 0; // sin(0f)
+ c[4] = 1; // cos(0f)
+
+ final int vboUsage = GL.GL_STATIC_DRAW;
+
+ frontFace = createInterleaved(useMappedBuffers, 6, GL.GL_FLOAT, false, 4*teeth+2, vboUsage);
+ addInterleavedVertexAndNormalArrays(frontFace, 3);
+ backFace = createInterleaved(useMappedBuffers, 6, GL.GL_FLOAT, false, 4*teeth+2, vboUsage);
+ addInterleavedVertexAndNormalArrays(backFace, 3);
+ frontSide = createInterleaved(useMappedBuffers, 6, GL.GL_FLOAT, false, 6*teeth, vboUsage);
+ addInterleavedVertexAndNormalArrays(frontSide, 3);
+ backSide = createInterleaved(useMappedBuffers, 6, GL.GL_FLOAT, false, 6*teeth, vboUsage);
+ addInterleavedVertexAndNormalArrays(backSide, 3);
+ outwardFace = createInterleaved(useMappedBuffers, 6, GL.GL_FLOAT, false, 4*4*teeth+2, vboUsage);
+ addInterleavedVertexAndNormalArrays(outwardFace, 3);
+ insideRadiusCyl = createInterleaved(useMappedBuffers, 6, GL.GL_FLOAT, false, 2*teeth+2, vboUsage);
+ addInterleavedVertexAndNormalArrays(insideRadiusCyl, 3);
+
+ if( useMappedBuffers ) {
+ frontFace.mapStorage(gl, GL.GL_WRITE_ONLY);
+ backFace.mapStorage(gl, GL.GL_WRITE_ONLY);
+ frontSide.mapStorage(gl, GL.GL_WRITE_ONLY);
+ backSide.mapStorage(gl, GL.GL_WRITE_ONLY);
+ outwardFace.mapStorage(gl, GL.GL_WRITE_ONLY);
+ insideRadiusCyl.mapStorage(gl, GL.GL_WRITE_ONLY);
+ }
+
+ for (i = 0; i < teeth; i++) {
+ angle = i * 2.0f * M_PI / teeth;
+ sincos(angle + da * 0f, s, 0, c, 0);
+ sincos(angle + da * 1f, s, 1, c, 1);
+ sincos(angle + da * 2f, s, 2, c, 2);
+ sincos(angle + da * 3f, s, 3, c, 3);
+
+ /* front */
+ normal[0] = 0.0f;
+ normal[1] = 0.0f;
+ normal[2] = 1.0f;
+
+ /* front face - GL.GL_TRIANGLE_STRIP */
+ vert(frontFace, r0 * c[0], r0 * s[0], dz, normal);
+ vert(frontFace, r1 * c[0], r1 * s[0], dz, normal);
+ vert(frontFace, r0 * c[0], r0 * s[0], dz, normal);
+ vert(frontFace, r1 * c[3], r1 * s[3], dz, normal);
+
+ /* front sides of teeth - GL.GL_TRIANGLES */
+ vert(frontSide, r1 * c[0], r1 * s[0], dz, normal);
+ vert(frontSide, r2 * c[1], r2 * s[1], dz, normal);
+ vert(frontSide, r2 * c[2], r2 * s[2], dz, normal);
+ vert(frontSide, r1 * c[0], r1 * s[0], dz, normal);
+ vert(frontSide, r2 * c[2], r2 * s[2], dz, normal);
+ vert(frontSide, r1 * c[3], r1 * s[3], dz, normal);
+
+ /* back */
+ normal[0] = 0.0f;
+ normal[1] = 0.0f;
+ normal[2] = -1.0f;
+
+ /* back face - GL.GL_TRIANGLE_STRIP */
+ vert(backFace, r1 * c[0], r1 * s[0], -dz, normal);
+ vert(backFace, r0 * c[0], r0 * s[0], -dz, normal);
+ vert(backFace, r1 * c[3], r1 * s[3], -dz, normal);
+ vert(backFace, r0 * c[0], r0 * s[0], -dz, normal);
+
+ /* back sides of teeth - GL.GL_TRIANGLES*/
+ vert(backSide, r1 * c[3], r1 * s[3], -dz, normal);
+ vert(backSide, r2 * c[2], r2 * s[2], -dz, normal);
+ vert(backSide, r2 * c[1], r2 * s[1], -dz, normal);
+ vert(backSide, r1 * c[3], r1 * s[3], -dz, normal);
+ vert(backSide, r2 * c[1], r2 * s[1], -dz, normal);
+ vert(backSide, r1 * c[0], r1 * s[0], -dz, normal);
+
+ /* outward faces of teeth */
+ u = r2 * c[1] - r1 * c[0];
+ v = r2 * s[1] - r1 * s[0];
+ len = (float)Math.sqrt(u * u + v * v);
+ u /= len;
+ v /= len;
+ normal[0] = v;
+ normal[1] = -u;
+ normal[2] = 0.0f;
+
+ vert(outwardFace, r1 * c[0], r1 * s[0], dz, normal);
+ vert(outwardFace, r1 * c[0], r1 * s[0], -dz, normal);
+ vert(outwardFace, r2 * c[1], r2 * s[1], dz, normal);
+ vert(outwardFace, r2 * c[1], r2 * s[1], -dz, normal);
+
+ normal[0] = c[0];
+ normal[1] = s[0];
+ vert(outwardFace, r2 * c[1], r2 * s[1], dz, normal);
+ vert(outwardFace, r2 * c[1], r2 * s[1], -dz, normal);
+ vert(outwardFace, r2 * c[2], r2 * s[2], dz, normal);
+ vert(outwardFace, r2 * c[2], r2 * s[2], -dz, normal);
+
+ normal[0] = ( r1 * s[3] - r2 * s[2] );
+ normal[1] = ( r1 * c[3] - r2 * c[2] ) * -1.0f ;
+ vert(outwardFace, r2 * c[2], r2 * s[2], dz, normal);
+ vert(outwardFace, r2 * c[2], r2 * s[2], -dz, normal);
+ vert(outwardFace, r1 * c[3], r1 * s[3], dz, normal);
+ vert(outwardFace, r1 * c[3], r1 * s[3], -dz, normal);
+
+ normal[0] = c[0];
+ normal[1] = s[0];
+ vert(outwardFace, r1 * c[3], r1 * s[3], dz, normal);
+ vert(outwardFace, r1 * c[3], r1 * s[3], -dz, normal);
+ vert(outwardFace, r1 * c[0], r1 * s[0], dz, normal);
+ vert(outwardFace, r1 * c[0], r1 * s[0], -dz, normal);
+
+ /* inside radius cylinder */
+ normal[0] = c[0] * -1.0f;
+ normal[1] = s[0] * -1.0f;
+ normal[2] = 0.0f;
+ vert(insideRadiusCyl, r0 * c[0], r0 * s[0], -dz, normal);
+ vert(insideRadiusCyl, r0 * c[0], r0 * s[0], dz, normal);
+ }
+ /* finish front face */
+ normal[0] = 0.0f;
+ normal[1] = 0.0f;
+ normal[2] = 1.0f;
+ vert(frontFace, r0 * c[4], r0 * s[4], dz, normal);
+ vert(frontFace, r1 * c[4], r1 * s[4], dz, normal);
+ frontFace.seal(true);
+
+ /* finish back face */
+ normal[2] = -1.0f;
+ vert(backFace, r1 * c[4], r1 * s[4], -dz, normal);
+ vert(backFace, r0 * c[4], r0 * s[4], -dz, normal);
+ backFace.seal(true);
+
+ backSide.seal(true);
+ frontSide.seal(true);
+
+ /* finish outward face */
+ sincos(da * 1f, s, 1, c, 1);
+ u = r2 * c[1] - r1 * c[4];
+ v = r2 * s[1] - r1 * s[4];
+ len = (float)Math.sqrt(u * u + v * v);
+ u /= len;
+ v /= len;
+ normal[0] = v;
+ normal[1] = -u;
+ normal[2] = 0.0f;
+ vert(outwardFace, r1 * c[4], r1 * s[4], dz, normal);
+ vert(outwardFace, r1 * c[4], r1 * s[4], -dz, normal);
+ outwardFace.seal(true);
+
+ /* finish inside radius cylinder */
+ normal[0] = c[4] * -1.0f;
+ normal[1] = s[4] * -1.0f;
+ normal[2] = 0.0f;
+ vert(insideRadiusCyl, r0 * c[4], r0 * s[4], -dz, normal);
+ vert(insideRadiusCyl, r0 * c[4], r0 * s[4], dz, normal);
+ insideRadiusCyl.seal(true);
+
+ if( useMappedBuffers ) {
+ frontFace.unmapStorage(gl);
+ backFace.unmapStorage(gl);
+ frontSide.unmapStorage(gl);
+ backSide.unmapStorage(gl);
+ outwardFace.unmapStorage(gl);
+ insideRadiusCyl.unmapStorage(gl);
+ } else {
+ /** Init VBO and data .. */
+ init(gl, frontFace);
+ init(gl, frontSide);
+ init(gl, backFace);
+ init(gl, backSide);
+ init(gl, outwardFace);
+ init(gl, insideRadiusCyl);
+ }
+ }
+
+ @Override
+ public String toString() {
+ final int ffVBO = null != frontFace ? frontFace.getVBOName() : 0;
+ final int fsVBO = null != frontSide ? frontSide.getVBOName() : 0;
+ final int bfVBO = null != backFace ? backFace.getVBOName() : 0;
+ final int bsVBO = null != backSide ? backSide.getVBOName() : 0;
+ return "GearsObj[0x"+Integer.toHexString(hashCode())+", vbo ff "+ffVBO+", fs "+fsVBO+", bf "+bfVBO+", bs "+bsVBO+"]";
+ }
+
+ static void vert(final GLArrayDataServer array, final float x, final float y, final float z, final float n[]) {
+ array.putf(x);
+ array.putf(y);
+ array.putf(z);
+ array.putf(n[0]);
+ array.putf(n[1]);
+ array.putf(n[2]);
+ }
+
+ static void sincos(final float x, final float sin[], final int sinIdx, final float cos[], final int cosIdx) {
+ sin[sinIdx] = (float) Math.sin(x);
+ cos[cosIdx] = (float) Math.cos(x);
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/PointsDemo.java b/src/demos/com/jogamp/opengl/demos/PointsDemo.java
new file mode 100644
index 000000000..749d37114
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/PointsDemo.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright 2012 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``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 JogAmp Community 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.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.demos;
+
+import com.jogamp.opengl.GLEventListener;
+
+public abstract class PointsDemo implements GLEventListener {
+ int swapInterval = 0;
+ final int edge = 8; // 8*8
+
+ public PointsDemo(final int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public PointsDemo() {
+ this.swapInterval = 1;
+ }
+
+ public abstract void setSmoothPoints(boolean v);
+
+ public abstract void setPointParams(float minSize, float maxSize, float distAttenConst, float distAttenLinear, float distAttenQuadratic, float fadeThreshold);
+
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/GearsES2.java b/src/demos/com/jogamp/opengl/demos/es2/GearsES2.java
new file mode 100644
index 000000000..a2d0f5db7
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/GearsES2.java
@@ -0,0 +1,673 @@
+/**
+ * Copyright (C) 2011 JogAmp Community. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+package com.jogamp.opengl.demos.es2;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.event.GestureHandler;
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.KeyListener;
+import com.jogamp.newt.event.MouseEvent;
+import com.jogamp.newt.event.MouseListener;
+import com.jogamp.newt.event.PinchToZoomGesture;
+import com.jogamp.newt.event.GestureHandler.GestureEvent;
+import com.jogamp.opengl.GLRendererQuirks;
+import com.jogamp.opengl.JoglVersion;
+import com.jogamp.opengl.math.FloatUtil;
+import com.jogamp.opengl.math.Quaternion;
+import com.jogamp.opengl.math.VectorUtil;
+import com.jogamp.opengl.util.CustomGLEventListener;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.TileRendererBase;
+import com.jogamp.opengl.util.glsl.ShaderCode;
+import com.jogamp.opengl.util.glsl.ShaderProgram;
+import com.jogamp.opengl.util.glsl.ShaderState;
+import com.jogamp.opengl.util.stereo.EyeParameter;
+import com.jogamp.opengl.util.stereo.ViewerPose;
+import com.jogamp.opengl.util.stereo.StereoGLEventListener;
+
+import java.nio.FloatBuffer;
+
+import com.jogamp.nativewindow.NativeWindow;
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLAnimatorControl;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLUniformData;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+
+import com.jogamp.opengl.demos.GearsObject;
+
+/**
+ * GearsES2.java <BR>
+ * @author Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P>
+ */
+public class GearsES2 implements StereoGLEventListener, TileRendererBase.TileRendererListener {
+ private final FloatBuffer lightPos = Buffers.newDirectFloatBuffer( new float[] { 5.0f, 5.0f, 10.0f } );
+
+ private ShaderState st = null;
+ private PMVMatrix pmvMatrix = null;
+ private GLUniformData pmvMatrixUniform = null;
+ private GLUniformData colorU = null;
+ private float view_rotx = 20.0f, view_roty = 30.0f;
+ private boolean flipVerticalInGLOrientation = false;
+ private final boolean customRendering = false;
+
+ private final float view_rotz = 0.0f;
+ private float panX = 0.0f, panY = 0.0f, panZ=0.0f;
+ private volatile GearsObjectES2 gear1=null, gear2=null, gear3=null;
+ private GearsES2 sharedGears = null;
+ private Object syncObjects = null;
+ private boolean useMappedBuffers = false;
+ private boolean validateBuffers = false;
+ private volatile boolean usesSharedGears = false;
+ private FloatBuffer gear1Color=GearsObject.red, gear2Color=GearsObject.green, gear3Color=GearsObject.blue;
+ private float angle = 0.0f;
+ private int swapInterval = 0;
+ // private MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter());
+ public MouseListener gearsMouse = new GearsMouseAdapter();
+ public KeyListener gearsKeys = new GearsKeyAdapter();
+ private TileRendererBase tileRendererInUse = null;
+ private boolean doRotateBeforePrinting;
+
+ private boolean doRotate = true;
+ private float[] clearColor = null;
+ private boolean clearBuffers = true;
+ private boolean verbose = true;
+ private volatile boolean isInit = false;
+
+ private PinchToZoomGesture pinchToZoomGesture = null;
+
+
+ public GearsES2(final int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public GearsES2() {
+ this.swapInterval = 1;
+ }
+
+ @Override
+ public void addTileRendererNotify(final TileRendererBase tr) {
+ tileRendererInUse = tr;
+ doRotateBeforePrinting = doRotate;
+ setDoRotation(false);
+ }
+ @Override
+ public void removeTileRendererNotify(final TileRendererBase tr) {
+ tileRendererInUse = null;
+ setDoRotation(doRotateBeforePrinting);
+ }
+ @Override
+ public void startTileRendering(final TileRendererBase tr) {
+ System.err.println("GearsES2.startTileRendering: "+sid()+""+tr);
+ }
+ @Override
+ public void endTileRendering(final TileRendererBase tr) {
+ System.err.println("GearsES2.endTileRendering: "+sid()+""+tr);
+ }
+
+ public void setDoRotation(final boolean rotate) { this.doRotate = rotate; }
+ public void setClearBuffers(final boolean v) { clearBuffers = v; }
+ public void setVerbose(final boolean v) { verbose = v; }
+ public void setFlipVerticalInGLOrientation(final boolean v) { flipVerticalInGLOrientation=v; }
+
+ /** float[4] */
+ public void setClearColor(final float[] clearColor) {
+ this.clearColor = clearColor;
+ }
+
+ public void setGearsColors(final FloatBuffer gear1Color, final FloatBuffer gear2Color, final FloatBuffer gear3Color) {
+ this.gear1Color = gear1Color;
+ this.gear2Color = gear2Color;
+ this.gear3Color = gear3Color;
+ }
+
+ public void setSharedGears(final GearsES2 shared) {
+ sharedGears = shared;
+ }
+
+ public void setSyncObjects(final Object sync) {
+ syncObjects = sync;
+ }
+
+ /**
+ * @return gear1
+ */
+ public GearsObjectES2 getGear1() { return gear1; }
+
+ /**
+ * @return gear2
+ */
+ public GearsObjectES2 getGear2() { return gear2; }
+
+ /**
+ * @return gear3
+ */
+ public GearsObjectES2 getGear3() { return gear3; }
+
+ public boolean usesSharedGears() { return usesSharedGears; }
+
+ public void setUseMappedBuffers(final boolean v) { useMappedBuffers = v; }
+ public void setValidateBuffers(final boolean v) { validateBuffers = v; }
+
+ public PMVMatrix getPMVMatrix() {
+ return pmvMatrix;
+ }
+
+ private static final int TIME_OUT = 2000; // 2s
+ private static final int POLL_DIVIDER = 20; // TO/20
+ private static final int TIME_SLICE = TIME_OUT / POLL_DIVIDER ;
+
+ /**
+ * @return True if this GLEventListener became initialized within TIME_OUT 2s
+ */
+ public boolean waitForInit(final boolean initialized) throws InterruptedException {
+ int wait;
+ for (wait=0; wait<POLL_DIVIDER && initialized != isInit ; wait++) {
+ Thread.sleep(TIME_SLICE);
+ }
+ return wait<POLL_DIVIDER;
+ }
+
+ private final String sid() { return "0x"+Integer.toHexString(hashCode()); }
+
+ @Override
+ public void init(final GLAutoDrawable drawable) {
+ if(null != sharedGears && !sharedGears.isInit() ) {
+ System.err.println(Thread.currentThread()+" GearsES2.init.0 "+sid()+": pending shared Gears .. re-init later XXXXX");
+ drawable.setGLEventListenerInitState(this, false);
+ return;
+ }
+
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" GearsES2.init.0 "+sid()+": tileRendererInUse "+tileRendererInUse+", "+this);
+ System.err.println("GearsES2 init "+sid()+" on "+Thread.currentThread());
+ System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
+ System.err.println("INIT GL IS: " + gl.getClass().getName());
+ System.err.println(JoglVersion.getGLStrings(gl, null, false).toString());
+ }
+ if( !gl.hasGLSL() ) {
+ System.err.println("No GLSL available, no rendering.");
+ return;
+ }
+
+ st = new ShaderState();
+ // st.setVerbose(true);
+ final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader",
+ "shader/bin", "gears", true);
+ final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader",
+ "shader/bin", "gears", true);
+ vp0.defaultShaderCustomization(gl, true, true);
+ fp0.defaultShaderCustomization(gl, true, true);
+ final ShaderProgram sp0 = new ShaderProgram();
+ sp0.add(gl, vp0, System.err);
+ sp0.add(gl, fp0, System.err);
+ st.attachShaderProgram(gl, sp0, true);
+ // Use debug pipeline
+ // drawable.setGL(new DebugGL(drawable.getGL()));
+
+ pmvMatrix = new PMVMatrix();
+ st.attachObject("pmvMatrix", pmvMatrix);
+ pmvMatrixUniform = new GLUniformData("pmvMatrix", 4, 4, pmvMatrix.glGetPMvMvitMatrixf()); // P, Mv, Mvi and Mvit
+ st.ownUniform(pmvMatrixUniform);
+ st.uniform(gl, pmvMatrixUniform);
+
+ final GLUniformData lightU = new GLUniformData("lightPos", 3, lightPos);
+ st.ownUniform(lightU);
+ st.uniform(gl, lightU);
+
+ colorU = new GLUniformData("color", 4, GearsObject.red);
+ st.ownUniform(colorU);
+ st.uniform(gl, colorU);
+
+ if( null != sharedGears ) {
+ gear1 = new GearsObjectES2(sharedGears.getGear1(), st, pmvMatrix, pmvMatrixUniform, colorU);
+ gear2 = new GearsObjectES2(sharedGears.getGear2(), st, pmvMatrix, pmvMatrixUniform, colorU);
+ gear3 = new GearsObjectES2(sharedGears.getGear3(), st, pmvMatrix, pmvMatrixUniform, colorU);
+ usesSharedGears = true;
+ if(verbose) {
+ System.err.println("gear1 "+sid()+" created w/ share: "+sharedGears.getGear1()+" -> "+gear1);
+ System.err.println("gear2 "+sid()+" created w/ share: "+sharedGears.getGear2()+" -> "+gear2);
+ System.err.println("gear3 "+sid()+" created w/ share: "+sharedGears.getGear3()+" -> "+gear3);
+ }
+ if( gl.getContext().hasRendererQuirk(GLRendererQuirks.NeedSharedObjectSync) ) {
+ syncObjects = sharedGears;
+ System.err.println("Shared GearsES2: Synchronized Objects due to quirk "+GLRendererQuirks.toString(GLRendererQuirks.NeedSharedObjectSync));
+ } else if( null == syncObjects ) {
+ syncObjects = new Object();
+ System.err.println("Shared GearsES2: Unsynchronized Objects");
+ }
+ } else {
+ gear1 = new GearsObjectES2(gl, useMappedBuffers, st, gear1Color, 1.0f, 4.0f, 1.0f, 20, 0.7f, pmvMatrix, pmvMatrixUniform, colorU, validateBuffers);
+ if(verbose) {
+ System.err.println("gear1 "+sid()+" created: "+gear1);
+ }
+
+ gear2 = new GearsObjectES2(gl, useMappedBuffers, st, gear2Color, 0.5f, 2.0f, 2.0f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU, validateBuffers);
+ if(verbose) {
+ System.err.println("gear2 "+sid()+" created: "+gear2);
+ }
+
+ gear3 = new GearsObjectES2(gl, useMappedBuffers, st, gear3Color, 1.3f, 2.0f, 0.5f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU, validateBuffers);
+ if(verbose) {
+ System.err.println("gear3 "+sid()+" created: "+gear2);
+ }
+ if( null == syncObjects ) {
+ syncObjects = new Object();
+ }
+ }
+
+ final Object upstreamWidget = drawable.getUpstreamWidget();
+ if (upstreamWidget instanceof Window) {
+ final Window window = (Window) upstreamWidget;
+ window.addMouseListener(gearsMouse);
+ window.addKeyListener(gearsKeys);
+ window.addGestureListener(pinchToZoomListener);
+ pinchToZoomGesture = new PinchToZoomGesture(drawable.getNativeSurface(), false);
+ window.addGestureHandler(pinchToZoomGesture);
+ }
+
+ st.useProgram(gl, false);
+
+ gl.glFinish(); // make sure .. for shared context (impacts OSX 10.9)
+
+ isInit = true;
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" GearsES2.init.X "+sid()+" FIN "+this);
+ }
+ }
+
+ public final boolean isInit() { return isInit; }
+
+ private final GestureHandler.GestureListener pinchToZoomListener = new GestureHandler.GestureListener() {
+ @Override
+ public void gestureDetected(final GestureEvent gh) {
+ final PinchToZoomGesture.ZoomEvent ze = (PinchToZoomGesture.ZoomEvent) gh;
+ final float zoom = ze.getZoom(); // * ( ze.getTrigger().getPointerCount() - 1 ); <- too much ..
+ panZ = zoom * 30f - 30f; // [0 .. 2] -> [-30f .. 30f]
+ }
+ };
+
+ @Override
+ public void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height) {
+ if( !isInit ) { return; }
+ final GL2ES2 gl = glad.getGL().getGL2ES2();
+ gl.setSwapInterval(swapInterval);
+ reshapeImpl(gl, x, y, width, height, width, height);
+ }
+
+ @Override
+ public void reshapeTile(final TileRendererBase tr,
+ final int tileX, final int tileY, final int tileWidth, final int tileHeight,
+ final int imageWidth, final int imageHeight) {
+ if( !isInit ) { return; }
+ final GL2ES2 gl = tr.getAttachedDrawable().getGL().getGL2ES2();
+ gl.setSwapInterval(0);
+ reshapeImpl(gl, tileX, tileY, tileWidth, tileHeight, imageWidth, imageHeight);
+ }
+
+ private float zNear = 5f;
+ private float zFar = 10000f;
+ private float zViewDist = 40.0f;
+
+ public void setZ(final float zNear, final float zFar, final float zViewDist) {
+ this.zNear = zNear;
+ this.zFar = zFar;
+ this.zViewDist = zViewDist;
+ }
+
+ void reshapeImpl(final GL2ES2 gl, final int tileX, final int tileY, final int tileWidth, final int tileHeight, final int imageWidth, final int imageHeight) {
+ final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers();
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" GearsES2.reshape "+sid()+" "+tileX+"/"+tileY+" "+tileWidth+"x"+tileHeight+" of "+imageWidth+"x"+imageHeight+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(gl.getContext().getGLDrawable().getHandle())+", msaa "+msaa+", tileRendererInUse "+tileRendererInUse);
+ }
+
+ if( !gl.hasGLSL() ) {
+ return;
+ }
+
+ // compute projection parameters 'normal'
+ float left, right, bottom, top;
+ if( imageHeight > imageWidth ) {
+ final float a = (float)imageHeight / (float)imageWidth;
+ left = -1.0f;
+ right = 1.0f;
+ bottom = -a;
+ top = a;
+ } else {
+ final float a = (float)imageWidth / (float)imageHeight;
+ left = -a;
+ right = a;
+ bottom = -1.0f;
+ top = 1.0f;
+ }
+ final float w = right - left;
+ final float h = top - bottom;
+
+ // compute projection parameters 'tiled'
+ final float l = left + tileX * w / imageWidth;
+ final float r = l + tileWidth * w / imageWidth;
+ final float b = bottom + tileY * h / imageHeight;
+ final float t = b + tileHeight * h / imageHeight;
+
+ final float _w = r - l;
+ final float _h = t - b;
+ if(verbose) {
+ System.err.println(">> GearsES2 "+sid()+", angle "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h+", v-flip "+flipVerticalInGLOrientation);
+ }
+
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ if( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) {
+ pmvMatrix.glScalef(1f, -1f, 1f);
+ }
+ pmvMatrix.glFrustumf(l, r, b, t, zNear, zFar);
+
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glTranslatef(0.0f, 0.0f, -zViewDist);
+ st.useProgram(gl, true);
+ st.uniform(gl, pmvMatrixUniform);
+ st.useProgram(gl, false);
+ }
+ // private boolean useAndroidDebug = false;
+
+ private final float[] mat4Tmp1 = new float[16];
+ private final float[] mat4Tmp2 = new float[16];
+ private final float[] vec3Tmp1 = new float[3];
+ private final float[] vec3Tmp2 = new float[3];
+ private final float[] vec3Tmp3 = new float[3];
+
+ private static final float[] vec3ScalePos = new float[] { 20f, 20f, 20f };
+
+ @Override
+ public void reshapeForEye(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height,
+ final EyeParameter eyeParam, final ViewerPose viewerPose) {
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ final float[] mat4Projection = FloatUtil.makePerspective(mat4Tmp1, 0, true, eyeParam.fovhv, zNear, zFar);
+ if( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() ) {
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glScalef(1f, -1f, 1f);
+ pmvMatrix.glMultMatrixf(mat4Projection, 0);
+ } else {
+ pmvMatrix.glLoadMatrixf(mat4Projection, 0);
+ }
+
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+
+ final Quaternion rollPitchYaw = new Quaternion();
+ // private final float eyeYaw = FloatUtil.PI; // 180 degrees in radians
+ // rollPitchYaw.rotateByAngleY(eyeYaw);
+ // final float[] shiftedEyePos = rollPitchYaw.rotateVector(vec3Tmp1, 0, viewerPose.position, 0);
+ final float[] shiftedEyePos = VectorUtil.copyVec3(vec3Tmp1, 0, viewerPose.position, 0);
+ VectorUtil.scaleVec3(shiftedEyePos, shiftedEyePos, vec3ScalePos); // amplify viewerPose position
+ VectorUtil.addVec3(shiftedEyePos, shiftedEyePos, eyeParam.positionOffset);
+
+ rollPitchYaw.mult(viewerPose.orientation);
+ final float[] up = rollPitchYaw.rotateVector(vec3Tmp2, 0, VectorUtil.VEC3_UNIT_Y, 0);
+ final float[] forward = rollPitchYaw.rotateVector(vec3Tmp3, 0, VectorUtil.VEC3_UNIT_Z_NEG, 0);
+ final float[] center = VectorUtil.addVec3(forward, shiftedEyePos, forward);
+
+ final float[] mLookAt = FloatUtil.makeLookAt(mat4Tmp1, 0, shiftedEyePos, 0, center, 0, up, 0, mat4Tmp2);
+ final float[] mViewAdjust = FloatUtil.makeTranslation(mat4Tmp2, true, eyeParam.distNoseToPupilX, eyeParam.distMiddleToPupilY, eyeParam.eyeReliefZ);
+ final float[] mat4Modelview = FloatUtil.multMatrix(mViewAdjust, mLookAt);
+
+ pmvMatrix.glLoadMatrixf(mat4Modelview, 0);
+ pmvMatrix.glTranslatef(0.0f, 0.0f, -zViewDist);
+ st.useProgram(gl, true);
+ st.uniform(gl, pmvMatrixUniform);
+ st.useProgram(gl, false);
+ }
+
+ @Override
+ public void dispose(final GLAutoDrawable drawable) {
+ if( !isInit ) { return; }
+ isInit = false;
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" GearsES2.dispose "+sid()+": tileRendererInUse "+tileRendererInUse);
+ }
+ final Object upstreamWidget = drawable.getUpstreamWidget();
+ if (upstreamWidget instanceof Window) {
+ final Window window = (Window) upstreamWidget;
+ window.removeMouseListener(gearsMouse);
+ window.removeKeyListener(gearsKeys);
+ window.removeGestureHandler(pinchToZoomGesture);
+ pinchToZoomGesture = null;
+ window.removeGestureListener(pinchToZoomListener);
+ }
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ if( !gl.hasGLSL() ) {
+ return;
+ }
+ st.useProgram(gl, false);
+ gear1.destroy(gl);
+ gear1 = null;
+ gear2.destroy(gl);
+ gear2 = null;
+ gear3.destroy(gl);
+ gear3 = null;
+ pmvMatrix = null;
+ colorU = null;
+ st.destroy(gl);
+ st = null;
+ sharedGears = null;
+ syncObjects = null;
+
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" GearsES2.dispose "+sid()+" FIN");
+ }
+ }
+
+ @Override
+ public void display(final GLAutoDrawable drawable) {
+ display(drawable, 0);
+ }
+
+ @Override
+ public void display(final GLAutoDrawable drawable, final int flags) {
+ if( !isInit ) { return; }
+ if(null != sharedGears && !sharedGears.isInit() ) { return; }
+ final GLAnimatorControl anim = drawable.getAnimator();
+ if( verbose && ( null == anim || !anim.isAnimating() ) ) {
+ System.err.println(Thread.currentThread()+" GearsES2.display "+sid()+" "+drawable.getSurfaceWidth()+"x"+drawable.getSurfaceHeight()+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(drawable.getHandle()));
+ }
+
+ final boolean repeatedFrame = 0 != ( CustomGLEventListener.DISPLAY_REPEAT & flags );
+ final boolean dontClear = 0 != ( CustomGLEventListener.DISPLAY_DONTCLEAR & flags );
+
+ // Turn the gears' teeth
+ if( doRotate && !repeatedFrame ) {
+ angle += 0.5f;
+ }
+
+ // Get the GL corresponding to the drawable we are animating
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ final boolean hasFocus;
+ final Object upstreamWidget = drawable.getUpstreamWidget();
+ if(upstreamWidget instanceof NativeWindow) {
+ hasFocus = ((NativeWindow)upstreamWidget).hasFocus();
+ } else {
+ hasFocus = true;
+ }
+
+ if( clearBuffers && !dontClear ) {
+ if( null != clearColor ) {
+ gl.glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
+ } else if( null != tileRendererInUse ) {
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
+ } else {
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ }
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ }
+ if( !gl.hasGLSL() ) {
+ return;
+ }
+
+ setGLStates(gl, true);
+
+ st.useProgram(gl, true);
+ pmvMatrix.glPushMatrix();
+ pmvMatrix.glTranslatef(panX, panY, panZ);
+ pmvMatrix.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
+ pmvMatrix.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
+ pmvMatrix.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
+
+ synchronized ( syncObjects ) {
+ gear1.draw(gl, -3.0f, -2.0f, 1f * angle - 0f);
+ gear2.draw(gl, 3.1f, -2.0f, -2f * angle - 9.0f);
+ gear3.draw(gl, -3.1f, 4.2f, -2f * angle - 25.0f);
+ }
+ pmvMatrix.glPopMatrix();
+ st.useProgram(gl, false);
+
+ setGLStates(gl, false);
+ }
+
+ public void setGLStates(final GL2ES2 gl, final boolean enable) {
+ // Culling only possible if we do not flip the projection matrix
+ final boolean useCullFace = ! ( flipVerticalInGLOrientation && gl.getContext().getGLDrawable().isGLOriented() || customRendering );
+ if( enable ) {
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ if( useCullFace ) {
+ gl.glEnable(GL.GL_CULL_FACE);
+ }
+ } else {
+ gl.glDisable(GL.GL_DEPTH_TEST);
+ if( useCullFace ) {
+ gl.glDisable(GL.GL_CULL_FACE);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "GearsES2[obj "+sid()+" isInit "+isInit+", usesShared "+usesSharedGears+", 1 "+gear1+", 2 "+gear2+", 3 "+gear3+", sharedGears "+sharedGears+"]";
+ }
+
+ class GearsKeyAdapter extends KeyAdapter {
+ public void keyPressed(final KeyEvent e) {
+ final int kc = e.getKeyCode();
+ if(KeyEvent.VK_LEFT == kc) {
+ view_roty -= 1;
+ } else if(KeyEvent.VK_RIGHT == kc) {
+ view_roty += 1;
+ } else if(KeyEvent.VK_UP == kc) {
+ view_rotx -= 1;
+ } else if(KeyEvent.VK_DOWN == kc) {
+ view_rotx += 1;
+ }
+ }
+ }
+
+ class GearsMouseAdapter implements MouseListener{
+ private int prevMouseX, prevMouseY;
+
+ @Override
+ public void mouseClicked(final MouseEvent e) {
+ }
+
+ @Override
+ public void mouseEntered(final MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExited(final MouseEvent e) {
+ }
+
+ @Override
+ public void mouseWheelMoved(final MouseEvent e) {
+ final float[] rot = e.getRotation();
+ if( e.isControlDown() ) {
+ // alternative zoom
+ final float incr = e.isShiftDown() ? rot[0] : rot[1] * 0.5f ;
+ panZ += incr;
+ System.err.println("panZ.2: incr "+incr+", dblZoom "+e.isShiftDown()+" -> "+panZ);
+ } else {
+ // panning
+ panX -= rot[0]; // positive -> left
+ panY += rot[1]; // positive -> up
+ }
+ }
+
+ public void mousePressed(final MouseEvent e) {
+ if( e.getPointerCount()==1 ) {
+ prevMouseX = e.getX();
+ prevMouseY = e.getY();
+ } else if( e.getPointerCount() == 4 ) {
+ final Object src = e.getSource();
+ if( e.getPressure(0, true) > 0.7f && src instanceof Window) { // show Keyboard
+ ((Window) src).setKeyboardVisible(true);
+ }
+ }
+ }
+
+ public void mouseReleased(final MouseEvent e) {
+ }
+
+ public void mouseMoved(final MouseEvent e) {
+ if( e.isConfined() ) {
+ navigate(e);
+ } else {
+ // track prev. position so we don't have 'jumps'
+ // in case we move to confined navigation.
+ prevMouseX = e.getX();
+ prevMouseY = e.getY();
+ }
+ }
+
+ public void mouseDragged(final MouseEvent e) {
+ navigate(e);
+ }
+
+ private void navigate(final MouseEvent e) {
+ final int x = e.getX();
+ final int y = e.getY();
+
+ int width, height;
+ final Object source = e.getSource();
+ Window window = null;
+ if(source instanceof Window) {
+ window = (Window) source;
+ width=window.getSurfaceWidth();
+ height=window.getSurfaceHeight();
+ } else if (source instanceof GLAutoDrawable) {
+ final GLAutoDrawable glad = (GLAutoDrawable) source;
+ width = glad.getSurfaceWidth();
+ height = glad.getSurfaceHeight();
+ } else {
+ throw new RuntimeException("Event source neither Window nor Component: "+source);
+ }
+ final float thetaY = 360.0f * ( (float)(x-prevMouseX)/(float)width);
+ final float thetaX = 360.0f * ( (float)(prevMouseY-y)/(float)height);
+ view_rotx += thetaX;
+ view_roty += thetaY;
+ prevMouseX = x;
+ prevMouseY = y;
+ // System.err.println("rotXY.1: "+view_rotx+"/"+view_roty+", source "+e);
+ }
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/GearsObjectES2.java b/src/demos/com/jogamp/opengl/demos/es2/GearsObjectES2.java
new file mode 100644
index 000000000..7266240b1
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/GearsObjectES2.java
@@ -0,0 +1,146 @@
+/**
+ * Copyright (C) 2011 JogAmp Community. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+package com.jogamp.opengl.demos.es2;
+
+import java.nio.FloatBuffer;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLBufferStorage;
+import com.jogamp.opengl.GLException;
+import com.jogamp.opengl.GLUniformData;
+
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+import com.jogamp.opengl.demos.GearsObject;
+
+/**
+ * GearsObjectES2.java <BR>
+ * @author Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P>
+ */
+public class GearsObjectES2 extends GearsObject {
+ final PMVMatrix pmvMatrix;
+ final GLUniformData pmvMatrixUniform;
+ final GLUniformData colorUniform;
+ final ShaderState st;
+
+ public GearsObjectES2(final GL gl, final boolean useMappedBuffers, final ShaderState st, final FloatBuffer gearColor,
+ final float inner_radius, final float outer_radius,
+ final float width,
+ final int teeth,
+ final float tooth_depth, final PMVMatrix pmvMatrix, final GLUniformData pmvMatrixUniform, final GLUniformData colorUniform, final boolean validateBuffers)
+ {
+ super(gl, useMappedBuffers, gearColor, inner_radius, outer_radius, width, teeth, tooth_depth, validateBuffers);
+ this.pmvMatrix = pmvMatrix;
+ this.pmvMatrixUniform = pmvMatrixUniform;
+ this.colorUniform = colorUniform;
+ this.st = st;
+ associate(st);
+ }
+
+ public GearsObjectES2(final GearsObjectES2 shared,
+ final ShaderState st,
+ final PMVMatrix pmvMatrix,
+ final GLUniformData pmvMatrixUniform, final GLUniformData colorUniform)
+ {
+ super(shared);
+ this.pmvMatrix = pmvMatrix;
+ this.pmvMatrixUniform = pmvMatrixUniform;
+ this.colorUniform = colorUniform;
+ this.st = st;
+ associate(st);
+ }
+
+ private void associate(final ShaderState st) {
+ frontFace.associate(st, true);
+ frontSide.associate(st, true);
+ backFace.associate(st, true);
+ backSide.associate(st, true);
+ outwardFace.associate(st, true);
+ insideRadiusCyl.associate(st, true);
+ }
+
+ @Override
+ public GLArrayDataServer createInterleaved(final boolean useMappedBuffers, final int comps, final int dataType, final boolean normalized, final int initialSize, final int vboUsage) {
+ if( useMappedBuffers ) {
+ return GLArrayDataServer.createGLSLInterleavedMapped(comps, dataType, normalized, initialSize, vboUsage);
+ } else {
+ return GLArrayDataServer.createGLSLInterleaved(comps, dataType, normalized, initialSize, vboUsage);
+ }
+ }
+
+ @Override
+ public void addInterleavedVertexAndNormalArrays(final GLArrayDataServer array, final int components) {
+ array.addGLSLSubArray("vertices", components, GL.GL_ARRAY_BUFFER);
+ array.addGLSLSubArray("normals", components, GL.GL_ARRAY_BUFFER);
+ }
+
+ private void draw(final GL2ES2 gl, final GLArrayDataServer array, final int mode, final int face) {
+ if( !isShared || gl.glIsBuffer(array.getVBOName()) ) {
+ if( validateBuffers ) {
+ array.bindBuffer(gl, true);
+ final int bufferTarget = array.getVBOTarget();
+ final int bufferName = array.getVBOName();
+ final long bufferSize = array.getSizeInBytes();
+ final int hasBufferName = gl.getBoundBuffer(bufferTarget);
+ final GLBufferStorage hasStorage = gl.getBufferStorage(hasBufferName);
+ final boolean ok = bufferName == hasBufferName &&
+ bufferName == hasStorage.getName() &&
+ bufferSize == hasStorage.getSize();
+ if( !ok ) {
+ throw new GLException("GLBufferStorage Validation Error: Target[exp 0x"+Integer.toHexString(bufferTarget)+", has 0x"+Integer.toHexString(bufferTarget)+
+ ", Name[exp "+bufferName+", has "+hasBufferName+", Size exp "+bufferSize+", Storage "+hasStorage+"]");
+ }
+ }
+ array.enableBuffer(gl, true);
+ // System.err.println("XXX Draw face "+face+" of "+this);
+ gl.glDrawArrays(mode, 0, array.getElementCount());
+ array.enableBuffer(gl, false);
+ }
+ }
+
+ @Override
+ public void draw(final GL _gl, final float x, final float y, final float angle) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ pmvMatrix.glPushMatrix();
+ pmvMatrix.glTranslatef(x, y, 0f);
+ pmvMatrix.glRotatef(angle, 0f, 0f, 1f);
+ if( pmvMatrix.update() ) {
+ st.uniform(gl, pmvMatrixUniform);
+ } else {
+ throw new InternalError("PMVMatrix.update() returns false after mutable operations");
+ }
+
+ colorUniform.setData(gearColor);
+ st.uniform(gl, colorUniform);
+
+ draw(gl, frontFace, GL.GL_TRIANGLE_STRIP, 0);
+ draw(gl, frontSide, GL.GL_TRIANGLES, 1);
+ draw(gl, backFace, GL.GL_TRIANGLE_STRIP, 2);
+ draw(gl, backSide, GL.GL_TRIANGLES, 3);
+ draw(gl, outwardFace, GL.GL_TRIANGLE_STRIP, 4);
+ draw(gl, insideRadiusCyl, GL.GL_TRIANGLE_STRIP, 5);
+
+ pmvMatrix.glPopMatrix();
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/LandscapeES2.java b/src/demos/com/jogamp/opengl/demos/es2/LandscapeES2.java
new file mode 100644
index 000000000..0a42ae302
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/LandscapeES2.java
@@ -0,0 +1,187 @@
+/**
+ * Copyright 2013 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``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 JogAmp Community 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.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.demos.es2;
+
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.glsl.ShaderCode;
+import com.jogamp.opengl.util.glsl.ShaderProgram;
+import com.jogamp.opengl.util.glsl.ShaderState;
+import java.nio.FloatBuffer;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.GLUniformData;
+
+/**
+ * LandscapeES2
+ */
+public class LandscapeES2 implements GLEventListener {
+ private int swapInterval = 0;
+ private boolean verbose = true;
+
+ static public final int TARGET_FPS = 120;
+ private long millisOffset;
+ private int frameCount;
+ private float frameRate;
+ private ShaderCode vertShader;
+ private ShaderCode fragShader;
+ private ShaderProgram shaderProg;
+ private ShaderState shaderState;
+ private float[] resolution;
+ private GLUniformData resolutionUni;
+ private GLUniformData timeUni;
+ private GLArrayDataServer vertices;
+
+ private int fcount = 0, lastm = 0;
+ private final int fint = 1;
+
+ public LandscapeES2(final int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public LandscapeES2() {
+ this.swapInterval = 1;
+ }
+
+ public void setVerbose(final boolean v) { verbose = v; }
+
+ public void init(final GLAutoDrawable drawable) {
+ System.err.println(Thread.currentThread()+" LandscapeES2.init ...");
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ if(verbose) {
+ System.err.println("LandscapeES2 init on "+Thread.currentThread());
+ System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
+ System.err.println("INIT GL IS: " + gl.getClass().getName());
+ System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));
+ System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));
+ System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
+ System.err.println("GL GLSL: "+gl.hasGLSL()+", has-compiler-func: "+gl.isFunctionAvailable("glCompileShader")+", version "+(gl.hasGLSL() ? gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION) : "none")+", "+gl.getContext().getGLSLVersionNumber());
+ System.err.println("GL FBO: basic "+ gl.hasBasicFBOSupport()+", full "+gl.hasFullFBOSupport());
+ System.err.println("GL Profile: "+gl.getGLProfile());
+ System.err.println("GL Renderer Quirks:" + gl.getContext().getRendererQuirks().toString());
+ System.err.println("GL:" + gl + ", " + gl.getContext().getGLVersion());
+ }
+
+ vertShader = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader", "shader/bin", "landscape", true);
+ fragShader = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader", "shader/bin", "landscape", true);
+ vertShader.defaultShaderCustomization(gl, true, true);
+ fragShader.defaultShaderCustomization(gl, true, true);
+ shaderProg = new ShaderProgram();
+ shaderProg.add(gl, vertShader, System.err);
+ shaderProg.add(gl, fragShader, System.err);
+
+ shaderState = new ShaderState();
+ shaderState.attachShaderProgram(gl, shaderProg, true);
+
+ resolution = new float[] { drawable.getSurfaceWidth(), drawable.getSurfaceHeight(), 0};
+ resolutionUni = new GLUniformData("iResolution", 3, FloatBuffer.wrap(resolution));
+ shaderState.ownUniform(resolutionUni);
+ shaderState.uniform(gl, resolutionUni);
+
+ timeUni = new GLUniformData("iGlobalTime", 0.0f);
+ shaderState.ownUniform(timeUni);
+
+ vertices = GLArrayDataServer.createGLSL("inVertex", 2, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
+ vertices.putf(-1.0f); vertices.putf(-1.0f);
+ vertices.putf(+1.0f); vertices.putf(-1.0f);
+ vertices.putf(-1.0f); vertices.putf(+1.0f);
+ vertices.putf(+1.0f); vertices.putf(+1.0f);
+ vertices.seal(gl, true);
+ shaderState.ownAttribute(vertices, true);
+ shaderState.useProgram(gl, false);
+
+ millisOffset = System.currentTimeMillis();
+
+ System.err.println(Thread.currentThread()+" LandscapeES2.init FIN");
+ }
+
+ public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
+ System.err.println(Thread.currentThread()+" LandscapeES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(drawable.getHandle()));
+
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+
+ gl.setSwapInterval(swapInterval); // in case switching the drawable (impl. may bound attribute there)
+
+ shaderState.useProgram(gl, true);
+
+ resolution[0] = drawable.getSurfaceWidth();
+ resolution[1] = drawable.getSurfaceHeight();
+ shaderState.uniform(gl, resolutionUni);
+
+ shaderState.useProgram(gl, false);
+ }
+
+ public void dispose(final GLAutoDrawable drawable) {
+ System.err.println(Thread.currentThread()+" LandscapeES2.dispose ... ");
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ shaderState.useProgram(gl, false);
+ shaderState.destroy(gl);
+ shaderState = null;
+
+ System.err.println(Thread.currentThread()+" LandscapeES2.dispose FIN");
+ }
+
+ public void display(final GLAutoDrawable drawable) {
+ final GL2ES2 gl = drawable.getGL().getGL2ES2();
+ // Shader fills complete framebuffer regardless of DEPTH, no Clear required.
+ // gl.glClearColor(0.5f, 0.1f, 0.1f, 1);
+ // gl.glClear(GL.GL_COLOR_BUFFER_BIT);
+
+ shaderState.useProgram(gl, true);
+
+ timeUni.setData((System.currentTimeMillis() - millisOffset) / 1000.0f);
+ shaderState.uniform(gl, timeUni);
+ vertices.enableBuffer(gl, true);
+ gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
+ vertices.enableBuffer(gl, false);
+
+ shaderState.useProgram(gl, false);
+
+ // Compute current framerate and printout.
+ frameCount++;
+ fcount += 1;
+ final int m = (int) (System.currentTimeMillis() - millisOffset);
+ if (m - lastm > 1000 * fint) {
+ frameRate = (float)(fcount) / fint;
+ fcount = 0;
+ lastm = m;
+ }
+ if (frameCount % TARGET_FPS == 0) {
+ System.out.println("FrameCount: " + frameCount + " - " + "FrameRate: " + frameRate);
+ }
+ }
+
+ boolean confinedFixedCenter = false;
+
+ public void setConfinedFixedCenter(final boolean v) {
+ confinedFixedCenter = v;
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/PointsDemoES2.java b/src/demos/com/jogamp/opengl/demos/es2/PointsDemoES2.java
new file mode 100644
index 000000000..0b4dac9b2
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/PointsDemoES2.java
@@ -0,0 +1,208 @@
+/**
+ * Copyright 2012 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``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 JogAmp Community 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.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.demos.es2;
+
+import java.nio.FloatBuffer;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.glsl.ShaderCode;
+import com.jogamp.opengl.util.glsl.ShaderProgram;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2ES1;
+import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GL2GL3;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLUniformData;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+
+import com.jogamp.opengl.demos.PointsDemo;
+
+public class PointsDemoES2 extends PointsDemo {
+ ShaderState st;
+ PMVMatrix pmvMatrix;
+ GLUniformData pmvMatrixUniform;
+ GLArrayDataServer vertices ;
+ GLArrayDataServer pointSizes ;
+ private int swapInterval = 0;
+ final int edge = 8; // 8*8
+ /** vec4[2]: { (sz, smooth, attnMinSz, attnMaxSz), (attnCoeff(3), attnFadeTs) } */
+ private static final String mgl_PointParams = "mgl_PointParams";
+
+ /** ( pointSize, pointSmooth, attn. pointMinSize, attn. pointMaxSize ) , ( attenuation coefficients 1f 0f 0f, attenuation fade theshold 1f ) */
+ private final FloatBuffer pointParams = Buffers.newDirectFloatBuffer(new float[] { 1.0f, 0.0f, 0.0f, 4096.0f, 1.0f, 0.0f, 0.0f, 1.0f });
+
+ public PointsDemoES2(final int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public PointsDemoES2() {
+ this.swapInterval = 1;
+ }
+
+ public void setSmoothPoints(final boolean v) {
+ pointParams.put(1, v ? 1.0f : 0.0f);
+ }
+
+ public void setPointParams(final float minSize, final float maxSize, final float distAttenConst, final float distAttenLinear, final float distAttenQuadratic, final float fadeThreshold) {
+ pointParams.put(2, minSize);
+ pointParams.put(3, maxSize);
+ pointParams.put(4+0, distAttenConst);
+ pointParams.put(4+1, distAttenLinear);
+ pointParams.put(4+2, distAttenQuadratic);
+ pointParams.put(4+3, fadeThreshold);
+ }
+
+ public void init(final GLAutoDrawable glad) {
+ final GL2ES2 gl = glad.getGL().getGL2ES2();
+
+ System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));
+ System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));
+ System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
+ System.err.println("GL GLSL: "+gl.hasGLSL()+", has-compiler-func: "+gl.isFunctionAvailable("glCompileShader")+", version "+(gl.hasGLSL() ? gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION) : "none"));
+ System.err.println("GL Profile: "+gl.getGLProfile());
+
+ st = new ShaderState();
+ st.setVerbose(true);
+ final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader",
+ "shader/bin", "PointsShader", true);
+ final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader",
+ "shader/bin", "PointsShader", true);
+ vp0.defaultShaderCustomization(gl, true, true);
+ fp0.defaultShaderCustomization(gl, true, true);
+ final ShaderProgram sp0 = new ShaderProgram();
+ sp0.add(gl, vp0, System.err);
+ sp0.add(gl, fp0, System.err);
+ st.attachShaderProgram(gl, sp0, true);
+
+ // setup mgl_PMVMatrix
+ pmvMatrix = new PMVMatrix();
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv
+ st.ownUniform(pmvMatrixUniform);
+ st.uniform(gl, pmvMatrixUniform);
+
+ st.uniform(gl, new GLUniformData(mgl_PointParams, 4, pointParams));
+
+ final GLUniformData colorStaticUniform = new GLUniformData("mgl_ColorStatic", 4, Buffers.newDirectFloatBuffer(new float[] { 1.0f, 1.0f, 1.0f, 1.0f }) );
+ st.uniform(gl, colorStaticUniform);
+ st.ownUniform(colorStaticUniform);
+
+ // Allocate Vertex Array
+ vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, edge*edge, GL.GL_STATIC_DRAW);
+ pointSizes = GLArrayDataServer.createGLSL("mgl_PointSize", 1, GL.GL_FLOAT, false, edge*edge, GL.GL_STATIC_DRAW);
+ for(int i=0; i<edge; i++) {
+ for(int j=0; j<edge; j++) {
+ final float x = -3+j*0.7f;
+ final float y = -3+i*0.7f;
+ final float p = (i*edge+j)*0.5f;
+ // System.err.println("["+j+"/"+i+"]: "+x+"/"+y+": "+p);
+ vertices.putf(x); vertices.putf(y); vertices.putf( 0);
+ pointSizes.putf(p);
+ }
+ }
+ vertices.seal(gl, true);
+ st.ownAttribute(vertices, true);
+ vertices.enableBuffer(gl, false);
+ pointSizes.seal(gl, true);
+ st.ownAttribute(pointSizes, true);
+ pointSizes.enableBuffer(gl, false);
+
+ // OpenGL Render Settings
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ st.useProgram(gl, false);
+ }
+
+ public void display(final GLAutoDrawable glad) {
+ final GL2ES2 gl = glad.getGL().getGL2ES2();
+ gl.glClearColor(0f, 0f, 0f, 0f);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ st.useProgram(gl, true);
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glTranslatef(0, 0, -10);
+ st.uniform(gl, pmvMatrixUniform);
+
+ final GLUniformData ud = st.getUniform(mgl_PointParams);
+ if(null!=ud) {
+ // same data object
+ st.uniform(gl, ud);
+ }
+
+ vertices.enableBuffer(gl, true);
+ pointSizes.enableBuffer(gl, true);
+
+ if(gl.isGL2GL3()) {
+ gl.glEnable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
+ }
+ if(gl.isGL2ES1()) {
+ gl.glEnable(GL2ES1.GL_POINT_SPRITE); // otherwise no gl_PointCoord
+ }
+ gl.glEnable ( GL.GL_BLEND );
+ gl.glBlendFunc ( GL.GL_SRC_ALPHA, GL.GL_ONE );
+
+ gl.glDrawArrays(GL.GL_POINTS, 0, edge*edge);
+
+ if(gl.isGL2GL3()) {
+ gl.glDisable(GL2GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
+ }
+
+ pointSizes.enableBuffer(gl, false);
+ vertices.enableBuffer(gl, false);
+ st.useProgram(gl, false);
+ }
+
+ public void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height) {
+ // Thread.dumpStack();
+ final GL2ES2 gl = glad.getGL().getGL2ES2();
+
+ gl.setSwapInterval(swapInterval); // in case switching the drawable (impl. may bound attribute there)
+
+ st.useProgram(gl, true);
+ // Set location in front of camera
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.gluPerspective(45.0F, ( (float) width / (float) height ) / 1.0f, 1.0F, 100.0F);
+ //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
+ st.uniform(gl, pmvMatrixUniform);
+ st.useProgram(gl, false);
+ }
+
+ public void dispose(final GLAutoDrawable glad) {
+ final GL2ES2 gl = glad.getGL().getGL2ES2();
+ st.destroy(gl);
+ st = null;
+ pmvMatrix = null;
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/RedSquareES2.java b/src/demos/com/jogamp/opengl/demos/es2/RedSquareES2.java
new file mode 100644
index 000000000..a6e1f5cd9
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/RedSquareES2.java
@@ -0,0 +1,274 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``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 JogAmp Community 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.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl.demos.es2;
+
+import com.jogamp.opengl.JoglVersion;
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.PMVMatrix;
+import com.jogamp.opengl.util.TileRendererBase;
+import com.jogamp.opengl.util.glsl.ShaderCode;
+import com.jogamp.opengl.util.glsl.ShaderProgram;
+import com.jogamp.opengl.util.glsl.ShaderState;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2ES2;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.GLUniformData;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+
+public class RedSquareES2 implements GLEventListener, TileRendererBase.TileRendererListener {
+ private ShaderState st;
+ private PMVMatrix pmvMatrix;
+ private GLUniformData pmvMatrixUniform;
+ private GLArrayDataServer vertices ;
+ private GLArrayDataServer colors ;
+ private long t0;
+ private int swapInterval = 0;
+ private float aspect = 1.0f;
+ private boolean doRotate = true;
+ private boolean verbose = true;
+ private boolean clearBuffers = true;
+ private TileRendererBase tileRendererInUse = null;
+ private boolean doRotateBeforePrinting;
+
+ public RedSquareES2(final int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public RedSquareES2() {
+ this.swapInterval = 1;
+ }
+
+ @Override
+ public void addTileRendererNotify(final TileRendererBase tr) {
+ tileRendererInUse = tr;
+ doRotateBeforePrinting = doRotate;
+ setDoRotation(false);
+ }
+ @Override
+ public void removeTileRendererNotify(final TileRendererBase tr) {
+ tileRendererInUse = null;
+ setDoRotation(doRotateBeforePrinting);
+ }
+ @Override
+ public void startTileRendering(final TileRendererBase tr) {
+ System.err.println("RedSquareES2.startTileRendering: "+tr);
+ }
+ @Override
+ public void endTileRendering(final TileRendererBase tr) {
+ System.err.println("RedSquareES2.endTileRendering: "+tr);
+ }
+
+ public void setAspect(final float aspect) { this.aspect = aspect; }
+ public void setDoRotation(final boolean rotate) { this.doRotate = rotate; }
+ public void setClearBuffers(final boolean v) { clearBuffers = v; }
+ public void setVerbose(final boolean v) { verbose = v; }
+
+ @Override
+ public void init(final GLAutoDrawable glad) {
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.init: tileRendererInUse "+tileRendererInUse);
+ }
+ final GL2ES2 gl = glad.getGL().getGL2ES2();
+
+ if(verbose) {
+ System.err.println("RedSquareES2 init on "+Thread.currentThread());
+ System.err.println("Chosen GLCapabilities: " + glad.getChosenGLCapabilities());
+ System.err.println("INIT GL IS: " + gl.getClass().getName());
+ System.err.println(JoglVersion.getGLStrings(gl, null, false).toString());
+ }
+ if( !gl.hasGLSL() ) {
+ System.err.println("No GLSL available, no rendering.");
+ return;
+ }
+ st = new ShaderState();
+ st.setVerbose(true);
+ final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(), "shader",
+ "shader/bin", "RedSquareShader", true);
+ final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader",
+ "shader/bin", "RedSquareShader", true);
+ vp0.defaultShaderCustomization(gl, true, true);
+ fp0.defaultShaderCustomization(gl, true, true);
+ final ShaderProgram sp0 = new ShaderProgram();
+ sp0.add(gl, vp0, System.err);
+ sp0.add(gl, fp0, System.err);
+ st.attachShaderProgram(gl, sp0, true);
+
+ // setup mgl_PMVMatrix
+ pmvMatrix = new PMVMatrix();
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv
+ st.ownUniform(pmvMatrixUniform);
+ st.uniform(gl, pmvMatrixUniform);
+
+ // Allocate Vertex Array
+ vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
+ vertices.putf(-2); vertices.putf( 2); vertices.putf( 0);
+ vertices.putf( 2); vertices.putf( 2); vertices.putf( 0);
+ vertices.putf(-2); vertices.putf(-2); vertices.putf( 0);
+ vertices.putf( 2); vertices.putf(-2); vertices.putf( 0);
+ vertices.seal(gl, true);
+ st.ownAttribute(vertices, true);
+ vertices.enableBuffer(gl, false);
+
+ // Allocate Color Array
+ colors= GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
+ colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1);
+ colors.putf(0); colors.putf(0); colors.putf(1); colors.putf(1);
+ colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1);
+ colors.putf(1); colors.putf(0); colors.putf(0); colors.putf(1);
+ colors.seal(gl, true);
+ st.ownAttribute(colors, true);
+ colors.enableBuffer(gl, false);
+
+ // OpenGL Render Settings
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ st.useProgram(gl, false);
+
+ t0 = System.currentTimeMillis();
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.init FIN");
+ }
+ }
+
+ @Override
+ public void display(final GLAutoDrawable glad) {
+ final long t1 = System.currentTimeMillis();
+
+ final GL2ES2 gl = glad.getGL().getGL2ES2();
+ if( clearBuffers ) {
+ if( null != tileRendererInUse ) {
+ gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
+ } else {
+ gl.glClearColor(0, 0, 0, 0);
+ }
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ }
+ if( !gl.hasGLSL() ) {
+ return;
+ }
+ st.useProgram(gl, true);
+ // One rotation every four seconds
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glTranslatef(0, 0, -10);
+ if(doRotate) {
+ final float ang = ((t1 - t0) * 360.0F) / 4000.0F;
+ pmvMatrix.glRotatef(ang, 0, 0, 1);
+ pmvMatrix.glRotatef(ang, 0, 1, 0);
+ }
+ st.uniform(gl, pmvMatrixUniform);
+
+ // Draw a square
+ vertices.enableBuffer(gl, true);
+ colors.enableBuffer(gl, true);
+ gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
+ vertices.enableBuffer(gl, false);
+ colors.enableBuffer(gl, false);
+ st.useProgram(gl, false);
+ }
+
+ @Override
+ public void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height) {
+ final GL2ES2 gl = glad.getGL().getGL2ES2();
+ gl.setSwapInterval(swapInterval);
+ reshapeImpl(gl, x, y, width, height, width, height);
+ }
+
+ @Override
+ public void reshapeTile(final TileRendererBase tr,
+ final int tileX, final int tileY, final int tileWidth, final int tileHeight,
+ final int imageWidth, final int imageHeight) {
+ final GL2ES2 gl = tr.getAttachedDrawable().getGL().getGL2ES2();
+ gl.setSwapInterval(0);
+ reshapeImpl(gl, tileX, tileY, tileWidth, tileHeight, imageWidth, imageHeight);
+ }
+
+ void reshapeImpl(final GL2ES2 gl, final int tileX, final int tileY, final int tileWidth, final int tileHeight, final int imageWidth, final int imageHeight) {
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.reshape "+tileX+"/"+tileY+" "+tileWidth+"x"+tileHeight+" of "+imageWidth+"x"+imageHeight+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(gl.getContext().getGLDrawable().getHandle())+", tileRendererInUse "+tileRendererInUse);
+ }
+ // Thread.dumpStack();
+ if( !gl.hasGLSL() ) {
+ return;
+ }
+
+ st.useProgram(gl, true);
+ // Set location in front of camera
+ pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+
+ // compute projection parameters 'normal' perspective
+ final float fovy=45f;
+ final float aspect2 = ( (float) imageWidth / (float) imageHeight ) / aspect;
+ final float zNear=1f;
+ final float zFar=100f;
+
+ // compute projection parameters 'normal' frustum
+ final float top=(float)Math.tan(fovy*((float)Math.PI)/360.0f)*zNear;
+ final float bottom=-1.0f*top;
+ final float left=aspect2*bottom;
+ final float right=aspect2*top;
+ final float w = right - left;
+ final float h = top - bottom;
+
+ // compute projection parameters 'tiled'
+ final float l = left + tileX * w / imageWidth;
+ final float r = l + tileWidth * w / imageWidth;
+ final float b = bottom + tileY * h / imageHeight;
+ final float t = b + tileHeight * h / imageHeight;
+
+ pmvMatrix.glFrustumf(l, r, b, t, zNear, zFar);
+ //pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
+ st.uniform(gl, pmvMatrixUniform);
+ st.useProgram(gl, false);
+
+ System.err.println(Thread.currentThread()+" RedSquareES2.reshape FIN");
+ }
+
+ @Override
+ public void dispose(final GLAutoDrawable glad) {
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.dispose: tileRendererInUse "+tileRendererInUse);
+ }
+ final GL2ES2 gl = glad.getGL().getGL2ES2();
+ if( !gl.hasGLSL() ) {
+ return;
+ }
+ st.destroy(gl);
+ st = null;
+ pmvMatrix = null;
+ if(verbose) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.dispose FIN");
+ }
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/PointsShader.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/PointsShader.fp
new file mode 100644
index 000000000..82268958f
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/PointsShader.fp
@@ -0,0 +1,53 @@
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+#else
+ #define MEDIUMP
+#endif
+
+// [0].rgba: 0, smooth, attnMinSz, attnMaxSz
+// [1].rgba: attnCoeff(3), attnFadeTs
+uniform MEDIUMP vec4 mgl_PointParams[2];
+
+#define pointSmooth (mgl_PointParams[0].g)
+
+varying vec4 frontColor;
+
+// #define TEST 1
+
+void main (void)
+{
+ mgl_FragColor = frontColor;
+
+ if( pointSmooth > 0.5 ) {
+ // smooth (AA)
+ const float border = 0.90; // take/give 10% for AA
+
+ // origin to 0/0, [-1/-1 .. 1/1]
+ vec2 pointPos = 2.0 * gl_PointCoord - 1.0 ;
+ float r = length( pointPos ); // one-circle sqrt(x * x + y * y), range: in-circle [0..1], out >1
+ float r1 = 1.0 - ( step(border, r) * 10.0 * ( r - border ) ) ; // [0..1]
+ #ifndef TEST
+ if( r1 < 0.0 ) {
+ discard;
+ }
+ #endif
+
+ #ifndef TEST
+ mgl_FragColor.a *= r1;
+ #else
+ mgl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
+ mgl_FragColor.r = r1 < 0.0 ? 1.0 : 0.0;
+ mgl_FragColor.g = r > 1.0 ? 1.0 : 0.0;
+ mgl_FragColor.b = r > border ? 1.0 : 0.0;
+ #endif
+ }
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/PointsShader.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/PointsShader.vp
new file mode 100644
index 000000000..562874785
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/PointsShader.vp
@@ -0,0 +1,53 @@
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+#else
+ #define MEDIUMP
+#endif
+
+uniform vec4 mgl_ColorStatic;
+uniform mat4 mgl_PMVMatrix[4]; // P, Mv, Mvi and Mvit (transpose(inverse(ModelView)) == normalMatrix)
+
+// [0].rgba: 0, smooth, attnMinSz, attnMaxSz
+// [1].rgba: attnCoeff(3), attnFadeTs
+uniform MEDIUMP vec4 mgl_PointParams[2];
+
+#define pointSmooth (mgl_PointParams[0].g)
+#define pointSizeMin (mgl_PointParams[0].b)
+#define pointSizeMax (mgl_PointParams[0].a)
+#define pointDistanceConstantAtten (mgl_PointParams[1].r)
+#define pointDistanceLinearAtten (mgl_PointParams[1].g)
+#define pointDistanceQuadraticAtten (mgl_PointParams[1].b)
+#define pointFadeThresholdSize (mgl_PointParams[1].a)
+
+attribute vec4 mgl_Vertex;
+attribute float mgl_PointSize;
+
+varying vec4 frontColor;
+
+void main(void)
+{
+ frontColor = mgl_ColorStatic;
+
+ vec4 eyeCoord = mgl_PMVMatrix[1] * mgl_Vertex;
+ gl_Position = mgl_PMVMatrix[0] * eyeCoord;
+
+ float dist = distance(eyeCoord, vec4(0.0, 0.0, 0.0, 1.0));
+ float atten = sqrt( 1.0 / ( pointDistanceConstantAtten +
+ ( pointDistanceLinearAtten +
+ pointDistanceQuadraticAtten * dist
+ ) * dist
+ )
+ );
+ float size = clamp(mgl_PointSize * atten, pointSizeMin, pointSizeMax);
+ gl_PointSize = max(size, pointFadeThresholdSize);
+
+ float fade = min(size, pointFadeThresholdSize) / pointFadeThresholdSize;
+ frontColor.a *= fade * fade;
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.fp
new file mode 100644
index 000000000..60b92401e
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.fp
@@ -0,0 +1,16 @@
+// Copyright 2010 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+varying vec4 frontColor;
+
+void main (void)
+{
+ mgl_FragColor = frontColor;
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.java b/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.java
new file mode 100644
index 000000000..1f07ef1db
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.java
@@ -0,0 +1,73 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``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 JogAmp Community 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.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.demos.es2.shader;
+
+public class RedSquareShader {
+ public static final String VERTEX_SHADER_TEXT =
+ " #ifdef GL_ES\n" +
+ " precision mediump float;\n" +
+ " precision mediump int;\n" +
+ "#endif\n" +
+ "\n" +
+ "#if __VERSION__ >= 130\n" +
+ " #define attribute in\n" +
+ " #define varying out\n" +
+ "#endif\n"+
+ "\n" +
+ "uniform mat4 mgl_PMVMatrix[2];\n" +
+ "attribute vec4 mgl_Vertex;\n" +
+ "attribute vec4 mgl_Color;\n" +
+ "varying vec4 frontColor;\n" +
+ "\n" +
+ "void main(void)\n" +
+ "{\n" +
+ " frontColor=mgl_Color;\n" +
+ " gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;\n" +
+ "}\n" ;
+
+ public static final String FRAGMENT_SHADER_TEXT =
+ " #ifdef GL_ES\n" +
+ " precision mediump float;\n" +
+ " precision mediump int;\n" +
+ "#endif\n" +
+ "\n" +
+ "#if __VERSION__ >= 130\n" +
+ " #define varying in\n" +
+ " out vec4 mgl_FragColor;\n" +
+ "#else\n" +
+ " #define mgl_FragColor gl_FragColor\n" +
+ "#endif\n" +
+ "\n" +
+ "varying vec4 frontColor;\n" +
+ "\n" +
+ "void main (void)\n" +
+ "{\n" +
+ " mgl_FragColor = frontColor;\n" +
+ "}\n" ;
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.vp
new file mode 100644
index 000000000..9283dd7bd
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader.vp
@@ -0,0 +1,18 @@
+// Copyright 2010 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+uniform mat4 mgl_PMVMatrix[2];
+attribute vec4 mgl_Vertex;
+attribute vec4 mgl_Color;
+varying vec4 frontColor;
+
+void main(void)
+{
+ frontColor=mgl_Color;
+ gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader2.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader2.fp
new file mode 100644
index 000000000..25a2df2d7
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/RedSquareShader2.fp
@@ -0,0 +1,16 @@
+// Copyright 2010 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+varying vec4 frontColor;
+
+void main (void)
+{
+ mgl_FragColor = vec4(0.0, frontColor.g, frontColor.b, 1.0);
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/default.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/default.vp
new file mode 100644
index 000000000..2037086f1
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/default.vp
@@ -0,0 +1,24 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+ #define HIGHP highp
+ #define LOWP lowp
+#else
+ #define MEDIUMP
+ #define HIGHP
+ #define LOWP
+#endif
+
+uniform HIGHP mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi
+attribute HIGHP vec4 gca_Vertices;
+
+void main(void)
+{
+ gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * gca_Vertices;
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/elektronenmultiplizierer_development.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/elektronenmultiplizierer_development.fp
new file mode 100644
index 000000000..60f054b46
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/elektronenmultiplizierer_development.fp
@@ -0,0 +1,389 @@
+/**
+ * Copyright 2011 JogAmp Community. All rights reserved.
+ *
+ * Details see: src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/ElektronenMultiplizierer.java
+ */
+
+/**
+ * http://www.youtube.com/user/DemoscenePassivist
+ * author: Dominik Stroehlein (DemoscenePassivist)
+ **/
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#ifdef GL_ES
+ precision mediump float;
+ precision mediump sampler2D;
+ precision mediump int;
+#endif
+
+uniform int en; //effectnumber
+uniform float et; //effecttime
+uniform sampler2D fb; //fbotexture
+uniform float br; //brightness
+uniform float tm; //time
+uniform vec2 resolution;//screen resolution/fbo resolution
+
+float camerafocallengthdode;
+vec3 camerapositiondode;
+vec2 sizedode;
+vec3 backgroundcolor = vec3(0,0.6,0.46);
+mat3 worldrotationxyz;
+mat3 fractalplanerotationx;
+mat3 fractalplanerotationy;
+mat3 camerarotationdode;
+vec2 oglFragCoord;
+
+//fractal formula used for sphreretracing/distance-estimation
+//dodecahedron serpinski (knighty)
+//http://www.fractalforums.com/index.php?topic=3158.msg16982#msg16982
+//normal vectors for the dodecahedra-siepinski folding planes are:
+//(phi^2, 1, -phi), (-phi, phi^2, 1), (1, -phi, phi^2), (-phi*(1+phi), phi^2-1, 1+phi), (1+phi, -phi*(1+phi), phi^2-1) and x=0, y=0, z=0 planes.
+
+//const pre-calc
+const float phi = 1.618;
+// Using math functions in initializers fails on MacOSX
+// const float _IKVNORM_ = 1.0 / sqrt(pow(phi * (1.0 + phi), 2.0) + pow(phi * phi - 1.0, 2.0) + pow(1.0 + phi, 2.0));
+const float _IKVNORM_ = 0.190989113930771;
+const float _C1_ = phi * (1.0 + phi) * _IKVNORM_;
+const float _C2_ = (phi * phi - 1.0) * _IKVNORM_;
+const float _1C_ = (1.0 + phi) * _IKVNORM_;
+const vec3 phi3 = vec3(0.5, 0.5 / phi, 0.5 * phi);
+const vec3 c3 = vec3(_C1_, _C2_, _1C_);
+
+vec3 distancefunction(vec3 w) {
+//!P center scale offset ...
+ vec3 offset;
+ if (en==6) {
+ offset = vec3(0.61,0.1*et,0.99);
+ } else {
+ offset = vec3(0.61,0.0,0.99);
+ }
+//!P center scale \0/ this is awesome for fadeins !!!
+ float scale = 2.;
+ w *= worldrotationxyz;
+ float d, t;
+ float md = 1000.0, cd = 0.0;
+//!P iterations (8) ... 2x see below
+ for (int i = 0; i < 8; i++) {
+ w *= fractalplanerotationx;
+ w = abs(w);
+ t = w.x * phi3.z + w.y * phi3.y - w.z * phi3.x;
+ if (t < 0.0) { w += vec3(-2.0, -2.0, 2.0) * t * phi3.zyx; }
+ t = -w.x * phi3.x + w.y * phi3.z + w.z * phi3.y;
+ if (t < 0.0) { w += vec3(2.0, -2.0, -2.0) * t * phi3.xzy; }
+ t = w.x * phi3.y - w.y * phi3.x + w.z * phi3.z;
+ if (t < 0.0) { w += vec3(-2.0, 2.0, -2.0) * t * phi3.yxz; }
+ t = -w.x * c3.x + w.y * c3.y + w.z * c3.z;
+ if (t < 0.0) { w += vec3(2.0, -2.0, -2.0) * t * c3.xyz; }
+ t = w.x * c3.z - w.y * c3.x + w.z * c3.y;
+ if (t < 0.0) { w += vec3(-2.0, 2.0, -2.0) * t * c3.zxy; }
+ w *= fractalplanerotationy;
+ w *= scale;
+ w -= offset * (scale - 1.0);
+ //accumulate minimum orbit for coloring ...
+ d = dot(w, w);
+//!P iterations for coloring (4)
+ if (i < 4) {
+ md = min(md, d);
+ cd = d;
+ }
+ }
+//!P max iterations (8)
+ return vec3((length(w) - 2.0) * pow(scale, -8.0), md, cd);
+}
+
+//calculate ray direction fragment coordinates
+vec3 raydirection(vec2 pixel) {
+ vec2 p = (0.5*sizedode-pixel)/vec2(sizedode.x,-sizedode.y);
+//!P aspect ratio of dode
+ p.x *= sizedode.x/sizedode.y;
+//!P vec3 w = vec3(0, 0, 1), vec3 v = vec3(0, 1, 0), vec3 u = vec3(1, 0, 0);
+ vec3 d = (p.x * vec3(1, 0, 0)+p.y * vec3(0, 1, 0)-camerafocallengthdode * vec3(0, 0, 1));
+ return normalize(camerarotationdode * d);
+}
+
+//iq's fake ambient occlusion
+//http://www.iquilezles.org/www/material/nvscene2008/rwwtt.pdf
+//http://www.iquilezles.org/www/articles/ao/ao.htm
+float ambientocclusion(vec3 p, vec3 n, float eps) {
+ float o = 1.0;
+//!P ao spread (10.6)
+// spreads the output color intensity
+ eps *= 10.6;
+//!P ao intensity (0.16)
+ float k = 0.16 / eps;
+ //add little start distance to the surface
+ float d = 2.0 * eps;
+//!P ao iterations (5) ...
+ for (int i = 0; i < 5; ++i) {
+ o -= (d - distancefunction(p + n * d).x) * k;
+ d += eps;
+ //fade ao when distance to the surface increases
+ k *= 0.5;
+ }
+ return clamp(o, 0.0, 1.0);
+}
+
+vec4 render(vec2 pixel) {
+ vec3 ray_direction = raydirection(pixel);
+//!P minimum ray length (6e-5)
+ float ray_length = 6e-5;
+ vec3 ray = camerapositiondode + ray_length * ray_direction;
+//!P minimum epsilon (6e-7) ...
+ float eps = 6e-7;
+ vec3 dist;
+ vec3 normal = vec3(0);
+ int steps = 0;
+ bool hit = false;
+ float minmarch = 0.0;
+//!P maxmarch = 10000.0;
+ float maxmarch = 25.0;
+//!P field of view scale = (1.0 / sqrt(1.0 + camerafocallengthdode * camerafocallengthdode))
+//!P detail of surface approximation = 1.22
+//!P pixelscale = (1.0 / min(sizedode.x, sizedode.y))
+ float epsfactor = 2.0 * (1.0 / sqrt(1.0 + camerafocallengthdode * camerafocallengthdode)) * (1.0 / min(sizedode.x, sizedode.y)) * 1.22;
+ ray_length = minmarch;
+ ray = camerapositiondode + ray_length * ray_direction;
+//!P max number of raymarching steps (90);
+ for (int i = 0; i < 90; i++) {
+ steps = i;
+ dist = distancefunction(ray);
+//!P X-) questionable surface smoothing (0.53)
+ dist.x *= 0.53;
+ //backtrack previous step and check if it was only a "fussel"
+ if (hit && dist.x < eps || ray_length > maxmarch || ray_length < minmarch) {
+ steps--;
+ break;
+ }
+ hit = false;
+ ray_length += dist.x;
+ ray = camerapositiondode + ray_length * ray_direction;
+ eps = ray_length * epsfactor;
+ if (dist.x < eps || ray_length < minmarch) {
+ hit = true;
+ }
+ }
+ //\0/ there is a hit!
+ vec4 color = vec4(backgroundcolor,0.5);
+ if (hit) {
+ float aof = 1.0;
+ if (steps < 1 || ray_length < minmarch) {
+ normal = normalize(ray);
+ } else {
+ //gradient in x,y and z direction for intersection point
+ //!P minimum normal (1.5e-7)
+ float e = max(eps * 0.5, 1.5e-7);
+ normal = normalize(vec3(
+ distancefunction(ray + vec3(e, 0, 0)).x - distancefunction(ray - vec3(e, 0, 0)).x,
+ distancefunction(ray + vec3(0, e, 0)).x - distancefunction(ray - vec3(0, e, 0)).x,
+ distancefunction(ray + vec3(0, 0, e)).x - distancefunction(ray - vec3(0, 0, e)).x
+ ));
+ aof = ambientocclusion(ray, normal, eps);
+ }
+//!P hardcoded light position vec3(-50,150,-25)
+ float diffuse = max(dot(normal, normalize(vec3(-50,150,-25) - ray)), 0.0);
+//blinn/phong specular stuff ...
+//!P specular exponent (4)
+//!P specularity (0.8)
+//!P diffuse color vec3(0.45) 2x in one line ...
+//!P ambient color vec2 ambientcolor = vec2(0.5,0.3)
+ color.rgb = (mix(vec3(0.5), backgroundcolor, 0.3) * vec3(0.45) + vec3(0.45) * diffuse + pow(diffuse, 4.) * 0.8)*aof;
+ color.a = 1.0;
+ }
+//!P fog factor = 0.01
+ color.rgb = mix(backgroundcolor, color.rgb, exp(-pow(ray_length, 2.0) * 0.01));
+ return color;
+}
+
+mat3 xmatrixrotation(float angle) {
+ return mat3(
+ vec3(1.0, 0.0, 0.0),
+ vec3(0.0, cos(angle), sin(angle)),
+ vec3(0.0, -sin(angle), cos(angle))
+ );
+}
+
+mat3 ymatrixrotation(float angle) {
+ return mat3(
+ vec3(cos(angle), 0.0, -sin(angle)),
+ vec3( 0.0, 1.0, 0.0),
+ vec3(sin(angle), 0.0, cos(angle))
+ );
+}
+
+vec4 raymarch_orbittrap_image(vec2 fragcoord) {
+ //do the matrix calculations by hand X-)
+ //as mat4 constructor and arithmetic assignments are
+ //currently broken (2010-09-21) on ATI cards i found
+ //a workaround using vec4 constructors wich works on
+ //both NVIDIA+ATI --- MAGIC. DO NOT TOUCH! -=#:-)
+ mat3 identitymatrix = mat3(1,0,0,0,1,0,0,0,1);
+ float sin_phi = sin(0.1*tm);
+ float cos_phi = cos(0.1*tm);
+ mat3 zrot = mat3(
+ vec3( cos_phi, sin_phi, 0.0),
+ vec3(-sin_phi, cos_phi, 0.0),
+ vec3( 0.0, 0.0, 1.0)
+ );
+ vec2 position;
+ float fractalplanex_var;
+ float fractalplaney_var;
+ position = oglFragCoord.xy;
+ camerafocallengthdode = 1.0;
+ if (en==2) {
+ sizedode = vec2(384,384);
+ camerapositiondode = vec3(0.0,0.0,-2.7);
+ } else if (en==3) {
+ camerapositiondode = vec3(0.0,0.0,-2.7*(10.-et));
+ } else if (en==4) {
+ camerapositiondode = vec3(0.0,0.0,-2.7*(10.-9.3));
+ fractalplanex_var = et;
+ fractalplaney_var = 0.0;
+ } else if (en==5) {
+ //inside effect
+ camerapositiondode = vec3(0.0,0.0,-0.05);
+ fractalplanex_var = 1.06;
+ fractalplaney_var = -1.0-et;
+ } else if (en==6) {
+ camerapositiondode = vec3(0.0,0.0,-2.7*(10.-9.5));
+ fractalplanex_var = et;
+ fractalplaney_var = sin(et*0.03)-1.0;
+ } else if (en==7) {
+ sizedode = vec2(384,384);
+ fractalplanex_var = et;
+ fractalplaney_var = sin(et*0.93)-1.0;
+ camerapositiondode = vec3(0.0,0.0,-2.7);
+ }
+ worldrotationxyz = xmatrixrotation(0.1*tm)*ymatrixrotation(0.1*tm)*zrot*identitymatrix;
+ fractalplanerotationx = xmatrixrotation(fractalplanex_var)*identitymatrix;
+ fractalplanerotationy = xmatrixrotation(fractalplaney_var)*identitymatrix;
+ camerarotationdode = ymatrixrotation(3.14)*identitymatrix;
+ vec4 color = render(position);
+ return color;
+}
+
+//----------------------------------------------------------------------------------------------------------
+
+vec4 orbitmapping(vec4 c, vec2 w) {
+//!P orbit trap scale and offset
+ vec2 orbittrapoffset = vec2(0.24,-0.24);
+ float orbittrapscale;
+ if (en==0) {
+ //julia set ...
+ orbittrapscale = 0.625;
+ } else {
+ //mandlebrot ...
+ orbittrapscale = 0.325;
+ }
+ vec2 sp = 0.5 + (w / orbittrapscale - orbittrapoffset);
+ vec4 s = texture2D(fb, sp);
+ if (s.a > 0.0) {
+ c = mix(c, s, s.a);
+ }
+ return c;
+}
+
+vec4 orbittrap(vec2 z) {
+ float powerjulia = 2.;
+ vec3 colorjulia = vec3(1.0);
+ vec4 color = vec4(colorjulia, 0.0);
+ float n = 0.0;
+ vec2 c;
+ if (en==0) {
+ //julia mode ...
+//!P use offset-julia from 2.25 to 2.5
+ c = vec2(sin(et+2.07)*0.05,cos(et+2.07));
+ } else {
+ //mandelbrot mode ...
+ c = z;
+ }
+//!P max iterations for julia (128) ... 2x parameter - see below!
+ for (int i = 0; i<128; i++) {
+ n += 1.0;
+ float r = pow(length(z), powerjulia);
+ float a = powerjulia * atan(z.y, z.x);
+ z = vec2(cos(a) * r, sin(a) * r) +c;
+//!P min iterations for julia (1.0) ...
+ if (n >= 1.0) {
+ color = orbitmapping(color, z);
+//!P orbit trap alpha precision (0.6) ...
+ if (color.a >= 0.6) {
+ break;
+ }
+ }
+ }
+//!P max iterations for julia (128.0) ...
+ float blend = clamp(1.0 - (n / 128.0) * 2.0, 0.0, 1.0);
+ color.rgb = mix(colorjulia, color.rgb, blend);
+ return color;
+}
+
+void main() {
+ vec2 sizejulia = resolution;
+ sizedode = sizejulia;
+ oglFragCoord = gl_FragCoord.xy;
+ vec4 color;
+ if (en==0 || en==1) {
+ //render 2d julia/mandelbrot
+//!P camera position for julia ...
+ vec3 camerapositionjulia;
+ if (en==0) {
+ //julia
+ camerapositionjulia = vec3(-0.2,-0.515,0.095347+(et*1.75));
+ } else {
+ //mandelbrot
+ camerapositionjulia = vec3(0.325895,0.049551,0.0005+et);
+ }
+//!P absolute output size of julia orbit trap ...
+ vec2 z = ((oglFragCoord.xy - (sizejulia * 0.5)) / sizejulia) *
+ vec2(sizejulia.x/sizejulia.y, 1.0) * //aspect ratio
+ camerapositionjulia.z +
+ camerapositionjulia.xy;
+ color = orbittrap(z);
+ } else {
+ color = raymarch_orbittrap_image(oglFragCoord.xy);
+ }
+ if (en==2 || en==7) {
+ mgl_FragColor = color;
+ } else {
+ //do normal rendering ...
+ //analog-tv distortion ...
+ vec2 position = oglFragCoord.xy / sizejulia.xy;
+ position.y *=-1.0;
+ vec3 color_tv = color.rgb;
+ //contrast
+ color_tv = clamp(color_tv*0.5+0.5*color_tv*color_tv*1.2,0.0,1.0);
+ //circular vignette fade
+ color_tv *= 0.5 + 0.5*16.0*position.x*position.y*(1.0-position.x)*(-1.0-position.y);
+ //color shift
+ if (en==0 || en==3) {
+ color_tv *= vec3(0.8,1.0,0.7); //green
+ }
+ if (en==1 || en==4) {
+ color_tv *= vec3(0.95,0.85,1.0); //blue
+ }
+ if (en==5) {
+ color_tv *= vec3(1.0,0.7,1.0); //purple
+ }
+
+ if (en==6) {
+ color_tv *= vec3(0.7,1.0,1.0); //cyan
+ }
+ if (en==2) {
+ color_tv *= vec3(1.0,1.0,0.7); //yellow
+ }
+ //tvlines effect
+ color_tv *= 0.9+0.1*sin(1.5*tm+position.y*1000.0);
+ //tv flicker effect
+ color_tv *= 0.97+0.13*sin(2.5*tm);
+ color_tv *= br;
+ mgl_FragColor = vec4(color_tv,1.0);
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/elektronenmultiplizierer_port.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/elektronenmultiplizierer_port.fp
new file mode 100644
index 000000000..77c34f74f
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/elektronenmultiplizierer_port.fp
@@ -0,0 +1,242 @@
+/**
+ * Copyright 2011 JogAmp Community. All rights reserved.
+ *
+ * Details see: src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/ElektronenMultiplizierer.java
+ */
+
+/**
+ * http://www.youtube.com/user/DemoscenePassivist
+ * author: Dominik Stroehlein (DemoscenePassivist)
+ **/
+
+//When I wrote this, only God and I understood what I was doing ...
+// ... now only God knows! X-)
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+uniform int en;
+uniform float et;
+uniform sampler2D fb;
+uniform float br,tm;
+uniform vec2 resolution;
+float v;
+vec3 n;
+vec2 e;
+vec3 f=vec3(0,.6,.46);
+mat3 i,m,r,y;
+vec2 c;
+const float x=1.618,t=1./sqrt(pow(x*(1.+x),2.)+pow(x*x-1.,2.)+pow(1.+x,2.)),z=x*(1.+x)*t,s=(x*x-1.)*t,w=(1.+x)*t;
+const vec3 a=vec3(.5,.5/x,.5*x),p=vec3(z,s,w);
+vec3 l(vec3 v) {
+ vec3 n;
+ if(en==6)
+ n=vec3(.61,.1*et,.99);
+ else
+ n=vec3(.61,0.,.99);
+ float e=2.;
+ v*=i;
+ float f,x,c=1000.,y=0.;
+ for(int z=0;z<8;z++) {
+ v*=m;
+ v=abs(v);
+ x=v.x*a.z+v.y*a.y-v.z*a.x;
+ if(x<0.)
+ v+=vec3(-2.,-2.,2.)*x*a.zyx;
+ x=-v.x*a.x+v.y*a.z+v.z*a.y;
+ if(x<0.)
+ v+=vec3(2.,-2.,-2.)*x*a.xzy;
+ x=v.x*a.y-v.y*a.x+v.z*a.z;
+ if(x<0.)
+ v+=vec3(-2.,2.,-2.)*x*a.yxz;
+ x=-v.x*p.x+v.y*p.y+v.z*p.z;
+ if(x<0.)
+ v+=vec3(2.,-2.,-2.)*x*p.xyz;
+ x=v.x*p.z-v.y*p.x+v.z*p.y;
+ if(x<0.)
+ v+=vec3(-2.,2.,-2.)*x*p.zxy;
+ v*=r;
+ v*=e;
+ v-=n*(e-1.);
+ f=dot(v,v);
+ if(z<4)
+ c=min(c,f),y=f;
+ }
+ return vec3((length(v)-2.)*pow(e,-8.),c,y);
+}
+vec3 b(vec2 x) {
+ vec2 n=(.5*e-x)/vec2(e.x,-e.y);
+ n.x*=e.x/e.y;
+ vec3 a=n.x*vec3(1,0,0)+n.y*vec3(0,1,0)-v*vec3(0,0,1);
+ return normalize(y*a);
+}
+float b(vec3 e,vec3 x,float v) {
+ float n=1.;
+ v*=10.6;
+ float t=.16/v,y=2.*v;
+ for(int i=0;i<5;++i)
+ n-=(y-l(e+x*y).x)*t,y+=v,t*=.5;
+ return clamp(n,0.,1.);
+}
+vec4 h(vec2 x) {
+ vec3 a=b(x);
+ float i=6e-05;
+ vec3 y=n+i*a;
+ float c=6e-07;
+ vec3 m,z=vec3(0);
+ int r=0;
+ bool t=false;
+ float s=0.,w=25.,p=2.*(1./sqrt(1.+v*v))*(1./min(e.x,e.y))*1.22;
+ i=s;
+ y=n+i*a;
+ for(int g=0;g<90;g++) {
+ r=g;
+ m=l(y);
+ m.x*=.53;
+ if(t&&m.x<c||i>w||i<s) {
+ r--;
+ break;
+ }
+ t=false;
+ i+=m.x;
+ y=n+i*a;
+ c=i*p;
+ if(m.x<c||i<s)
+ t=true;
+ }
+ vec4 g=vec4(f,.5);
+ if(t) {
+ float d=1.;
+ if(r<1||i<s)
+ z=normalize(y);
+ else {
+ float h=max(c*.5,1.5e-07);
+ z=normalize(vec3(l(y+vec3(h,0,0)).x-l(y-vec3(h,0,0)).x,l(y+vec3(0,h,0)).x-l(y-vec3(0,h,0)).x,l(y+vec3(0,0,h)).x-l(y-vec3(0,0,h)).x));
+ d=b(y,z,c);
+ }
+ float h=max(dot(z,normalize(vec3(-66,162,-30)-y)),0.);
+ g.xyz=(mix(vec3(.5),f,.3)*vec3(.45)+vec3(.45)*h+pow(h,4.)*.8)*d;
+ g.w=1.;
+ }
+ g.xyz=mix(f,g.xyz,exp(-pow(i,2.)*.01));
+ return g;
+}
+mat3 g(float e) {
+ return mat3(vec3(1.,0.,0.),vec3(0.,cos(e),sin(e)),vec3(0.,-sin(e),cos(e)));
+}
+mat3 d(float e) {
+ return mat3(vec3(cos(e),0.,-sin(e)),vec3(0.,1.,0.),vec3(sin(e),0.,cos(e)));
+}
+vec4 D(vec2 x) {
+ mat3 a=mat3(1,0,0,0,1,0,0,0,1);
+ float t=sin(.1*tm),z=cos(.1*tm);
+ mat3 p=mat3(vec3(z,t,0.),vec3(-t,z,0.),vec3(0.,0.,1.));
+ vec2 f;
+ float s,w;
+ f=c.xy;
+ v=1.;
+ if(en==2)
+ e=vec2(384,384),n=vec3(0.,0.,-2.7);
+ if(en==3)
+ n=vec3(0.,0.,-2.7*(10.-et));
+ if(en==4)
+ n=vec3(0.,0.,-1.89),s=et,w=0.;
+ if(en==5)
+ n=vec3(0.,0.,-.05),s=1.06,w=-1.-et;
+ if(en==6)
+ n=vec3(0.,0.,-1.35),s=et,w=sin(et*.03)-1.;
+ if(en==7)
+ e=vec2(384,384),s=et,w=sin(et*.93)-1.,n=vec3(0.,0.,-2.7);
+ i=g(.1*tm)*d(.1*tm)*p*a;
+ m=g(s)*a;
+ r=g(w)*a;
+ y=d(3.14)*a;
+ vec4 l=h(f);
+ if(l.w<.00392) {
+ discard;
+ }
+ return l;
+}
+vec4 D(vec4 e,vec2 x) {
+ vec2 n=vec2(.24,-.24);
+ float y;
+ if(en==0)
+ y=.625;
+ else
+ y=.325;
+ vec2 v=.5+(x/y-n);
+ vec4 c=texture2D(fb,v);
+ if(c.w>0.)
+ e=mix(e,c,c.w);
+ return e;
+}
+vec4 o(vec2 v) {
+ float n=2.;
+ vec3 e=vec3(1.);
+ vec4 i=vec4(e,0.);
+ float y=0.;
+ vec2 x;
+ if(en==0)
+ x=vec2(sin(et+2.07)*.05,cos(et+2.07));
+ else
+ x=v;
+ for(int f=0;f<128;f++) {
+ y+=1.;
+ float t=pow(length(v),n),c=n*atan(v.y,v.x);
+ v=vec2(cos(c)*t,sin(c)*t)+x;
+ if(y>=1.) {
+ i=D(i,v);
+ if(i.w>=.6) {
+ break;
+ }
+ }
+ }
+ float c=clamp(1.-y/128.*2.,0.,1.);
+ i.xyz=mix(e,i.xyz,c);
+ return i;
+}
+void main() {
+ //vec2 v=vec2(640.0,480.0);
+ vec2 v =resolution;
+ e=v;
+ c=gl_FragCoord.xy;
+ vec4 n;
+ if(en==0||en==1) {
+ vec3 a;
+ if(en==0)
+ a=vec3(-.2,-.515,.095347+et*1.75);
+ else
+ a=vec3(.325895,.049551,.0005+et);
+ vec2 x=(c.xy-v*.5)/v*vec2(v.x/v.y,1.)*a.z+a.xy;
+ n=o(x);
+ } else
+ n=D(c.xy);
+ if(en==2||en==7)
+ mgl_FragColor=n;
+ else {
+ vec2 i=c.xy/v.xy;
+ i.y*=-1.;
+ vec3 x=n.xyz;
+ x=clamp(x*.5+.5*x*x*1.2,0.,1.);
+ x*=.5+8.*i.x*i.y*(1.-i.x)*(-1.-i.y);
+ if(en==0||en==3)
+ x*=vec3(.8,1.,.7);
+ if(en==1||en==4)
+ x*=vec3(.95,.85,1.);
+ if(en==5)
+ x*=vec3(1.,.7,1.);
+ if(en==6)
+ x*=vec3(.7,1.,1.);
+ if(en==2)
+ x*=vec3(1.,1.,.7);
+ x*=.9+.1*sin(1.5*tm+i.y*1000.);
+ x*=.97+.13*sin(2.5*tm);
+ x*=br;
+ mgl_FragColor=vec4(x,1.);
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-1.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-1.fp
new file mode 100644
index 000000000..563e0a4b0
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-1.fp
@@ -0,0 +1,16 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragData[2];
+#else
+ #define mgl_FragData gl_FragData
+#endif
+
+varying vec4 frontColor;
+
+void main (void)
+{
+ mgl_FragData[0] = vec4( frontColor.r, 0.0, 0.0, 1.0 );
+ mgl_FragData[1] = vec4( 0.0, frontColor.g, 0.0, 1.0 );
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-1.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-1.vp
new file mode 100644
index 000000000..4cab59c64
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-1.vp
@@ -0,0 +1,19 @@
+// Copyright 2010 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+uniform mat4 gcu_PMVMatrix[2]; // P, Mv, and Mvi
+attribute vec4 gca_Vertices;
+attribute vec4 gca_Colors;
+
+varying vec4 frontColor;
+
+void main(void)
+{
+ frontColor = gca_Colors;
+ gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * gca_Vertices;
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-2.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-2.fp
new file mode 100644
index 000000000..510096d66
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-2.fp
@@ -0,0 +1,22 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragData[2];
+ #define texture2D texture
+#else
+ #define mgl_FragData gl_FragData
+#endif
+
+uniform sampler2D gcs_TexUnit0;
+uniform sampler2D gcs_TexUnit1;
+
+varying vec4 frontColor;
+varying vec2 texCoord;
+
+void main (void)
+{
+ vec2 rg = texture2D(gcs_TexUnit0, texCoord).rg + texture2D(gcs_TexUnit1, texCoord).rg;
+ float b = frontColor.b - length(rg);
+ mgl_FragData[0] = vec4( rg, b, 1.0 );
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-2.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-2.vp
new file mode 100644
index 000000000..89290b05a
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/fbo-mrt-2.vp
@@ -0,0 +1,21 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+uniform mat4 gcu_PMVMatrix[2]; // P, Mv, and Mvi
+attribute vec4 gca_Vertices;
+attribute vec4 gca_Colors;
+attribute vec2 gca_TexCoords;
+
+varying vec4 frontColor;
+varying vec2 texCoord;
+
+void main(void)
+{
+ frontColor = gca_Colors;
+ texCoord = gca_TexCoords;
+ gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * gca_Vertices;
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/gears.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/gears.fp
new file mode 100644
index 000000000..14328dc1e
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/gears.fp
@@ -0,0 +1,48 @@
+// Copyright (C) 2011 JogAmp Community. All rights reserved.
+// Details see GearsES2.java
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+uniform vec4 color;
+
+varying vec3 normal;
+varying vec4 position;
+varying vec3 lightDir;
+varying float attenuation;
+varying vec3 cameraDir;
+
+// Defining The Material Colors
+const vec4 matAmbient = vec4(0.2, 0.2, 0.2, 1.0); // orig default
+const vec4 matDiffuse = vec4(0.8, 0.8, 0.8, 1.0); // orig default
+// const vec4 matSpecular = vec4(0.0, 0.0, 0.0, 1.0); // orig default
+const vec4 matSpecular = vec4(0.8, 0.8, 0.8, 1.0);
+// const float matShininess = 0.0; // orig default
+const float matShininess = 0.5;
+
+void main()
+{
+ vec4 ambient = color * matAmbient;
+ vec4 specular = vec4(0.0);
+
+ float lambertTerm = dot(normal, lightDir);
+ vec4 diffuse = color * lambertTerm * attenuation * matDiffuse;
+ if (lambertTerm > 0.0) {
+ float NdotHV;
+ /*
+ vec3 halfDir = normalize (lightDir + cameraDir);
+ NdotHV = max(0.0, dot(normal, halfDir));
+ */
+ vec3 E = normalize(-position.xyz);
+ vec3 R = reflect(-lightDir, normal);
+ NdotHV = max(0.0, dot(R, E));
+
+ specular += color * pow(NdotHV, matShininess) * attenuation * matSpecular;
+ }
+
+ mgl_FragColor = ambient + diffuse + specular ;
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/gears.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/gears.vp
new file mode 100644
index 000000000..24f4f9c52
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/gears.vp
@@ -0,0 +1,45 @@
+// Copyright (C) 2011 JogAmp Community. All rights reserved.
+// Details see GearsES2.java
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+uniform mat4 pmvMatrix[4]; // P, Mv, Mvi and Mvit
+uniform vec3 lightPos;
+
+attribute vec4 vertices;
+attribute vec4 normals;
+
+varying vec3 normal;
+varying vec4 position;
+varying vec3 lightDir;
+varying float attenuation;
+varying vec3 cameraDir;
+
+const float constantAttenuation = 0.5; // 1.0;
+const float linearAttenuation = 0.001; // 0.0;
+const float quadraticAttenuation= 0.0002; // 0.0;
+
+void main(void)
+{
+ // Transforming The Vertex Position To ModelView-Space
+ position = pmvMatrix[1] * vertices; // vertex eye position
+
+ // incl. projection
+ gl_Position = pmvMatrix[0] * position;
+
+ // Transforming The Normal To ModelView-Space
+ normal = normalize((pmvMatrix[3] * normals).xyz);
+
+ // Calculating The Vector From The Vertex Position To The Light Position
+ lightDir = lightPos - position.xyz;
+ float d = length(lightDir);
+ attenuation = 1.0 / (
+ constantAttenuation +
+ linearAttenuation * d +
+ quadraticAttenuation * d * d );
+ lightDir = normalize(lightDir);
+ cameraDir = normalize((pmvMatrix[2] * vec4(0,0,0,1.0)).xyz - vertices.xyz);
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/landscape.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/landscape.fp
new file mode 100644
index 000000000..b19c057d3
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/landscape.fp
@@ -0,0 +1,339 @@
+// Elevated shader
+// https://www.shadertoy.com/view/MdX3Rr by inigo quilez
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+uniform vec3 iResolution;
+uniform float iGlobalTime;
+
+// Created by inigo quilez - iq/2013
+// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
+
+//stereo thanks to Croqueteer
+//#define STEREO
+
+mat3 m = mat3( 0.00, 0.80, 0.60,
+ -0.80, 0.36, -0.48,
+ -0.60, -0.48, 0.64 );
+
+float hash( float n )
+{
+ return fract(sin(n)*43758.5453123);
+}
+
+
+float noise( in vec3 x )
+{
+ vec3 p = floor(x);
+ vec3 f = fract(x);
+
+ f = f*f*(3.0-2.0*f);
+
+ float n = p.x + p.y*57.0 + 113.0*p.z;
+
+ float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
+ mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
+ mix(mix( hash(n+113.0), hash(n+114.0),f.x),
+ mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
+ return res;
+}
+
+
+
+
+vec3 noised( in vec2 x )
+{
+ vec2 p = floor(x);
+ vec2 f = fract(x);
+
+ vec2 u = f*f*(3.0-2.0*f);
+
+ float n = p.x + p.y*57.0;
+
+ float a = hash(n+ 0.0);
+ float b = hash(n+ 1.0);
+ float c = hash(n+ 57.0);
+ float d = hash(n+ 58.0);
+ return vec3(a+(b-a)*u.x+(c-a)*u.y+(a-b-c+d)*u.x*u.y,
+ 30.0*f*f*(f*(f-2.0)+1.0)*(vec2(b-a,c-a)+(a-b-c+d)*u.yx));
+
+}
+
+float noise( in vec2 x )
+{
+ vec2 p = floor(x);
+ vec2 f = fract(x);
+
+ f = f*f*(3.0-2.0*f);
+
+ float n = p.x + p.y*57.0;
+
+ float res = mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
+ mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
+
+ return res;
+}
+
+float fbm( vec3 p )
+{
+ float f = 0.0;
+
+ f += 0.5000*noise( p ); p = m*p*2.02;
+ f += 0.2500*noise( p ); p = m*p*2.03;
+ f += 0.1250*noise( p ); p = m*p*2.01;
+ f += 0.0625*noise( p );
+
+ return f/0.9375;
+}
+
+mat2 m2 = mat2(1.6,-1.2,1.2,1.6);
+
+float fbm( vec2 p )
+{
+ float f = 0.0;
+
+ f += 0.5000*noise( p ); p = m2*p*2.02;
+ f += 0.2500*noise( p ); p = m2*p*2.03;
+ f += 0.1250*noise( p ); p = m2*p*2.01;
+ f += 0.0625*noise( p );
+
+ return f/0.9375;
+}
+
+float terrain( in vec2 x )
+{
+ vec2 p = x*0.003;
+ float a = 0.0;
+ float b = 1.0;
+ vec2 d = vec2(0.0);
+ for(int i=0;i<5; i++)
+ {
+ vec3 n = noised(p);
+ d += n.yz;
+ a += b*n.x/(1.0+dot(d,d));
+ b *= 0.5;
+ p=mat2(1.6,-1.2,1.2,1.6)*p;
+ }
+
+ return 140.0*a;
+}
+
+float terrain2( in vec2 x )
+{
+ vec2 p = x*0.003;
+ float a = 0.0;
+ float b = 1.0;
+ vec2 d = vec2(0.0);
+ for(int i=0;i<14; i++)
+ {
+ vec3 n = noised(p);
+ d += n.yz;
+ a += b*n.x/(1.0+dot(d,d));
+ b *= 0.5;
+ p=m2*p;
+ }
+
+ return 140.0*a;
+}
+
+
+float map( in vec3 p )
+{
+ float h = terrain(p.xz);
+
+ float ss = 0.03;
+ float hh = h*ss;
+ float fh = fract(hh);
+ float ih = floor(hh);
+ fh = mix( sqrt(fh), fh, smoothstep(50.0,140.0,h) );
+ h = (ih+fh)/ss;
+
+ return p.y - h;
+}
+
+float map2( in vec3 p )
+{
+ float h = terrain2(p.xz);
+
+
+ float ss = 0.03;
+ float hh = h*ss;
+ float fh = fract(hh);
+ float ih = floor(hh);
+ fh = mix( sqrt(fh), fh, smoothstep(50.0,140.0,h) );
+ h = (ih+fh)/ss;
+
+ return p.y - h;
+}
+
+bool jinteresct(in vec3 rO, in vec3 rD, out float resT )
+{
+ float h = 0.0;
+ float t = 0.0;
+ for( int j=0; j<120; j++ )
+ {
+ //if( t>2000.0 ) break;
+
+ vec3 p = rO + t*rD;
+if( p.y>300.0 ) break;
+ h = map( p );
+
+ if( h<0.1 )
+ {
+ resT = t;
+ return true;
+ }
+ t += max(0.1,0.5*h);
+
+ }
+
+ if( h<5.0 )
+ {
+ resT = t;
+ return true;
+ }
+ return false;
+}
+
+float sinteresct(in vec3 rO, in vec3 rD )
+{
+ float res = 1.0;
+ float t = 0.0;
+ for( int j=0; j<50; j++ )
+ {
+ //if( t>1000.0 ) break;
+ vec3 p = rO + t*rD;
+
+ float h = map( p );
+
+ if( h<0.1 )
+ {
+ return 0.0;
+ }
+ res = min( res, 16.0*h/t );
+ t += h;
+
+ }
+
+ return clamp( res, 0.0, 1.0 );
+}
+
+vec3 calcNormal( in vec3 pos, float t )
+{
+ float e = 0.001;
+ e = 0.001*t;
+ vec3 eps = vec3(e,0.0,0.0);
+ vec3 nor;
+ nor.x = map2(pos+eps.xyy) - map2(pos-eps.xyy);
+ nor.y = map2(pos+eps.yxy) - map2(pos-eps.yxy);
+ nor.z = map2(pos+eps.yyx) - map2(pos-eps.yyx);
+ return normalize(nor);
+}
+
+vec3 camPath( float time )
+{
+ vec2 p = 600.0*vec2( cos(1.4+0.37*time),
+ cos(3.2+0.31*time) );
+
+ return vec3( p.x, 0.0, p.y );
+}
+
+void main(void)
+{
+ vec2 xy = -1.0 + 2.0*gl_FragCoord.xy / iResolution.xy;
+
+ vec2 s = xy*vec2(1.75,1.0);
+
+ #ifdef STEREO
+ float isCyan = mod(gl_FragCoord.x + mod(gl_FragCoord.y,2.0),2.0);
+ #endif
+
+ float time = iGlobalTime*.15;
+
+ vec3 light1 = normalize( vec3( 0.4, 0.22, 0.6 ) );
+ vec3 light2 = vec3( -0.707, 0.000, -0.707 );
+
+
+ vec3 campos = camPath( time );
+ vec3 camtar = camPath( time + 3.0 );
+ campos.y = terrain( campos.xz ) + 15.0;
+ camtar.y = campos.y*0.5;
+
+ float roll = 0.1*cos(0.1*time);
+ vec3 cw = normalize(camtar-campos);
+ vec3 cp = vec3(sin(roll), cos(roll),0.0);
+ vec3 cu = normalize(cross(cw,cp));
+ vec3 cv = normalize(cross(cu,cw));
+ vec3 rd = normalize( s.x*cu + s.y*cv + 1.6*cw );
+
+ #ifdef STEREO
+ campos += 2.0*cu*isCyan; // move camera to the right - the rd vector is still good
+ #endif
+
+ float sundot = clamp(dot(rd,light1),0.0,1.0);
+ vec3 col;
+ float t;
+ if( !jinteresct(campos,rd,t) )
+ {
+ col = 0.9*vec3(0.97,.99,1.0)*(1.0-0.3*rd.y);
+ col += 0.2*vec3(0.8,0.7,0.5)*pow( sundot, 4.0 );
+ }
+ else
+ {
+ vec3 pos = campos + t*rd;
+
+ vec3 nor = calcNormal( pos, t );
+
+ float dif1 = clamp( dot( light1, nor ), 0.0, 1.0 );
+ float dif2 = clamp( 0.2 + 0.8*dot( light2, nor ), 0.0, 1.0 );
+ float sh = 1.0;
+ if( dif1>0.001 )
+ sh = sinteresct(pos+light1*20.0,light1);
+
+ vec3 dif1v = vec3(dif1);
+ dif1v *= vec3( sh, sh*sh*0.5+0.5*sh, sh*sh );
+
+ float r = noise( 7.0*pos.xz );
+
+ col = (r*0.25+0.75)*0.9*mix( vec3(0.10,0.05,0.03), vec3(0.13,0.10,0.08), clamp(terrain2( vec2(pos.x,pos.y*48.0))/200.0,0.0,1.0) );
+ col = mix( col, 0.17*vec3(0.5,.23,0.04)*(0.50+0.50*r),smoothstep(0.70,0.9,nor.y) );
+ col = mix( col, 0.10*vec3(0.2,.30,0.00)*(0.25+0.75*r),smoothstep(0.95,1.0,nor.y) );
+ col *= 0.75;
+ // snow
+ #if 1
+ float h = smoothstep(55.0,80.0,pos.y + 25.0*fbm(0.01*pos.xz) );
+ float e = smoothstep(1.0-0.5*h,1.0-0.1*h,nor.y);
+ float o = 0.3 + 0.7*smoothstep(0.0,0.1,nor.x+h*h);
+ float s = h*e*o;
+ s = smoothstep( 0.1, 0.9, s );
+ col = mix( col, 0.4*vec3(0.6,0.65,0.7), s );
+ #endif
+
+
+ vec3 brdf = 2.0*vec3(0.17,0.19,0.20)*clamp(nor.y,0.0,1.0);
+ brdf += 6.0*vec3(1.00,0.95,0.80)*dif1v;
+ brdf += 2.0*vec3(0.20,0.20,0.20)*dif2;
+
+ col *= brdf;
+
+ float fo = 1.0-exp(-pow(0.0015*t,1.5));
+ vec3 fco = vec3(0.7) + 0.6*vec3(0.8,0.7,0.5)*pow( sundot, 4.0 );
+ col = mix( col, fco, fo );
+ }
+
+ col = sqrt(col);
+
+ vec2 uv = xy*0.5+0.5;
+ col *= 0.7 + 0.3*pow(16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y),0.1);
+
+ #ifdef STEREO
+ col *= vec3( isCyan, 1.0-isCyan, 1.0-isCyan );
+ #endif
+
+ mgl_FragColor = vec4(col,1.0);
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/landscape.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/landscape.vp
new file mode 100644
index 000000000..fc698f2a8
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/landscape.vp
@@ -0,0 +1,11 @@
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+attribute vec2 inVertex;
+
+void main() {
+ gl_Position = vec4(inVertex, 0, 1);
+} \ No newline at end of file
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/mgl_default_xxx.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/mgl_default_xxx.fp
new file mode 100644
index 000000000..a2abf9e2c
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/mgl_default_xxx.fp
@@ -0,0 +1,16 @@
+// Copyright 2012 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+varying vec4 frontColor;
+
+void main (void)
+{
+ mgl_FragColor = frontColor;
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/mgl_default_xxx.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/mgl_default_xxx.vp
new file mode 100644
index 000000000..98e7916ab
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/mgl_default_xxx.vp
@@ -0,0 +1,18 @@
+//Copyright 2012 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+uniform mat4 mgl_PMVMatrix[2]; // P, Mv
+attribute vec4 mgl_Vertex;
+attribute vec4 mgl_Color;
+
+varying vec4 frontColor;
+
+void main(void)
+{
+ frontColor = mgl_Color;
+ gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/ruler.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/ruler.fp
new file mode 100644
index 000000000..f16a3eeb1
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/ruler.fp
@@ -0,0 +1,33 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+#ifdef GL_ES
+ #define MEDIUMP mediump
+ #define HIGHP highp
+ #define LOWP lowp
+#else
+ #define MEDIUMP
+ #define HIGHP
+ #define LOWP
+#endif
+
+uniform MEDIUMP vec3 gcu_RulerColor;
+uniform MEDIUMP vec2 gcu_RulerPixFreq;
+
+const MEDIUMP vec2 onev2 = vec2(1.0, 1.0);
+
+void main (void)
+{
+ MEDIUMP vec2 c = step( onev2, mod(gl_FragCoord.xy, gcu_RulerPixFreq) );
+ if( c.s == 0.0 || c.t == 0.0 ) {
+ mgl_FragColor = vec4(gcu_RulerColor, 1.0);
+ } else {
+ discard;
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/texsequence_xxx.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/texsequence_xxx.fp
new file mode 100644
index 000000000..e4f21f95f
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/texsequence_xxx.fp
@@ -0,0 +1,30 @@
+// Copyright 2012 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+varying vec2 mgl_texCoord;
+varying vec4 frontColor;
+
+// Insert dynamic code after the following tag:
+// TEXTURE-SEQUENCE-CODE-BEGIN
+// TEXTURE-SEQUENCE-CODE-END
+
+void main (void)
+{
+ vec4 texColor;
+ if(0.0 <= mgl_texCoord.t && mgl_texCoord.t<=1.0) {
+ texColor = myTexture2D(mgl_ActiveTexture, mgl_texCoord);
+ } else {
+ texColor = vec4(1, 1, 1, 1);
+ }
+
+ // mix frontColor with texture ..
+ mgl_FragColor = vec4(frontColor*texColor);
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/texsequence_xxx.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/texsequence_xxx.vp
new file mode 100644
index 000000000..1030dab47
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/texsequence_xxx.vp
@@ -0,0 +1,22 @@
+// Copyright 2012 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+uniform mat4 mgl_PMVMatrix[2];
+// uniform mat4 mgl_STMatrix;
+attribute vec4 mgl_Vertex;
+attribute vec4 mgl_Color;
+attribute vec4 mgl_MultiTexCoord;
+varying vec4 frontColor;
+varying vec2 mgl_texCoord;
+
+void main(void)
+{
+ frontColor=mgl_Color;
+ // mgl_texCoord = (mgl_STMatrix * mgl_MultiTexCoord).st;
+ mgl_texCoord = mgl_MultiTexCoord.st;
+ gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/texture01_xxx.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/texture01_xxx.fp
new file mode 100644
index 000000000..93f252cd6
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/texture01_xxx.fp
@@ -0,0 +1,28 @@
+// Copyright 2012 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+varying vec2 mgl_texCoord;
+varying vec4 frontColor;
+
+uniform sampler2D mgl_ActiveTexture;
+
+void main (void)
+{
+ vec4 texColor;
+ if(0.0 <= mgl_texCoord.t && mgl_texCoord.t<=1.0) {
+ texColor = texture2D(mgl_ActiveTexture, mgl_texCoord);
+ } else {
+ discard;
+ }
+
+ // mix frontColor with texture .. pre-multiplying texture alpha
+ mgl_FragColor = vec4( mix( frontColor.rgb, texColor.rgb, texColor.a ), frontColor.a );
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/texture01_xxx.vp b/src/demos/com/jogamp/opengl/demos/es2/shader/texture01_xxx.vp
new file mode 100644
index 000000000..1030dab47
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/texture01_xxx.vp
@@ -0,0 +1,22 @@
+// Copyright 2012 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define attribute in
+ #define varying out
+#endif
+
+uniform mat4 mgl_PMVMatrix[2];
+// uniform mat4 mgl_STMatrix;
+attribute vec4 mgl_Vertex;
+attribute vec4 mgl_Color;
+attribute vec4 mgl_MultiTexCoord;
+varying vec4 frontColor;
+varying vec2 mgl_texCoord;
+
+void main(void)
+{
+ frontColor=mgl_Color;
+ // mgl_texCoord = (mgl_STMatrix * mgl_MultiTexCoord).st;
+ mgl_texCoord = mgl_MultiTexCoord.st;
+ gl_Position = mgl_PMVMatrix[0] * mgl_PMVMatrix[1] * mgl_Vertex;
+}
diff --git a/src/demos/com/jogamp/opengl/demos/es2/shader/texture02_xxx.fp b/src/demos/com/jogamp/opengl/demos/es2/shader/texture02_xxx.fp
new file mode 100644
index 000000000..10073e85c
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/es2/shader/texture02_xxx.fp
@@ -0,0 +1,28 @@
+// Copyright 2012 JogAmp Community. All rights reserved.
+
+#if __VERSION__ >= 130
+ #define varying in
+ out vec4 mgl_FragColor;
+ #define texture2D texture
+#else
+ #define mgl_FragColor gl_FragColor
+#endif
+
+varying vec2 mgl_texCoord;
+varying vec4 frontColor;
+
+uniform sampler2D mgl_Texture0;
+uniform sampler2D mgl_Texture1;
+
+const vec4 One = vec4(1.0, 1.0, 1.0, 1.0);
+
+void main (void)
+{
+ vec4 texColor0 = texture2D(mgl_Texture0, mgl_texCoord);
+ vec4 texColor1 = texture2D(mgl_Texture1, mgl_texCoord);
+
+ // mgl_FragColor = ( ( texColor0 + texColor1 ) / 2.0 ) * frontColor;
+ // mgl_FragColor = mix(texColor0, texColor1, One/2.0) * frontColor;
+ mgl_FragColor = min(One, mix(texColor0, texColor1, One/2.0) * 1.6) * frontColor;
+}
+
diff --git a/src/demos/com/jogamp/opengl/demos/ios/Hello.java b/src/demos/com/jogamp/opengl/demos/ios/Hello.java
new file mode 100644
index 000000000..d593dd3bc
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/ios/Hello.java
@@ -0,0 +1,196 @@
+/**
+ * Copyright 2019 Gothel Software e.K. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Gothel Software e.K. ``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 Gothel Software e.K. 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.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of Gothel Software e.K.
+ */
+package com.jogamp.opengl.demos.ios;
+
+import com.jogamp.common.util.ReflectionUtil;
+import com.jogamp.common.util.VersionUtil;
+import com.jogamp.nativewindow.AbstractGraphicsScreen;
+import com.jogamp.nativewindow.MutableGraphicsConfiguration;
+import com.jogamp.nativewindow.NativeWindowFactory;
+import com.jogamp.nativewindow.UpstreamWindowHookMutableSizePos;
+
+import com.jogamp.common.GlueGenVersion;
+import com.jogamp.opengl.JoglVersion;
+import com.jogamp.opengl.demos.es2.RedSquareES2;
+
+import jogamp.nativewindow.WrappedWindow;
+import jogamp.nativewindow.ios.IOSUtil;
+import jogamp.opengl.GLDrawableFactoryImpl;
+
+import com.jogamp.opengl.GLAutoDrawableDelegate;
+import com.jogamp.opengl.GLCapabilities;
+import com.jogamp.opengl.GLCapabilitiesImmutable;
+import com.jogamp.opengl.GLDrawable;
+import com.jogamp.opengl.GLDrawableFactory;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.GLProfile;
+
+public class Hello {
+
+ private static int parseInt(final String s, final int def) {
+ try {
+ return Integer.parseInt(s);
+ } catch (final NumberFormatException nfe) {}
+ return def;
+ }
+
+ public static void main(final String[] args) {
+ int width = 832, height = 480; // ipad pro 11: 2388x1668 px (scale: 2)
+ int fboDepthBits = 0; // CAEAGLLayer fails with depth 16 + 24 in Simulation
+ boolean exitJVM = false;
+ String demoName = "com.jogamp.opengl.demos.es2.LandscapeES2";
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-exit")) {
+ exitJVM = true;
+ } else if(args[i].equals("-demo") && i+1<args.length) {
+ demoName = args[++i];
+ } else if(args[i].equals("-width") && i+1<args.length) {
+ width = parseInt(args[++i], width);
+ } else if(args[i].equals("-height") && i+1<args.length) {
+ height = parseInt(args[++i], height);
+ } else if(args[i].equals("-fboDepthBits") && i+1<args.length) {
+ fboDepthBits = parseInt(args[++i], fboDepthBits);
+ } else {
+ System.err.println("ignoring arg["+i+"]: "+args[i]);
+ }
+ }
+ System.out.println("Hello JogAmp World: exitJVM "+exitJVM+", size "+width+"x"+height+", fboDepthBits "+fboDepthBits+", demo "+demoName);
+ System.out.println("os.name: <"+System.getProperty("os.name")+">");
+ System.out.println("os.version: <"+System.getProperty("os.version")+">");
+ System.out.println("os.arch: <"+System.getProperty("os.arch")+">");
+ System.out.println("java.vendor: <"+System.getProperty("java.vendor")+">");
+ System.out.println("java.vendor.url: <"+System.getProperty("java.vendor.url")+">");
+ System.out.println("java.version: <"+System.getProperty("java.version")+">");
+ System.out.println("java.vm.name: <"+System.getProperty("java.vm.name")+">");
+ System.out.println("java.runtime.name: <"+System.getProperty("java.runtime.name")+">");
+ System.out.println("");
+ System.out.println(VersionUtil.getPlatformInfo());
+ System.out.println("");
+ System.out.println("Version Info:");
+ System.out.println(GlueGenVersion.getInstance());
+ System.out.println("");
+ System.out.println("Full Manifest:");
+ System.out.println(GlueGenVersion.getInstance().getFullManifestInfo(null));
+
+ System.out.println("");
+ System.err.println("mark-01");
+ System.err.println("");
+ System.err.println(JoglVersion.getInstance());
+ System.err.println("");
+ System.err.println("mark-02");
+ System.err.println("");
+ GLProfile.initSingleton();
+ System.err.println("");
+ System.err.println("mark-03");
+ System.out.println("");
+ System.out.println(JoglVersion.getDefaultOpenGLInfo(GLProfile.getDefaultDevice(), null, true));
+ System.out.println("");
+ System.err.println("mark-04");
+ System.err.println("");
+
+ GLAutoDrawableDelegate glad = null;
+ final long uiWindow = IOSUtil.CreateUIWindow(0, 0, width, height);
+ try {
+ // 1) Config ..
+ final GLProfile glp = GLProfile.getGL2ES2();
+ final GLCapabilities reqCaps = new GLCapabilities(glp);
+ reqCaps.setOnscreen(true);
+ reqCaps.setDoubleBuffered(false);
+ reqCaps.setDepthBits(fboDepthBits);
+ System.out.println("Requested GL Caps: "+reqCaps);
+ final GLDrawableFactoryImpl factory = (GLDrawableFactoryImpl) GLDrawableFactory.getFactory(glp);
+
+ // 2) Create native window and wrap it around out NativeWindow structure
+ final long uiView = IOSUtil.GetUIView(uiWindow, true);
+ final long caeaglLayer = IOSUtil.GetCAEAGLLayer(uiView);
+ System.out.println("EAGL: UIWindow 0x"+Long.toHexString(uiWindow));
+ System.out.println("EAGL: UIView 0x"+Long.toHexString(uiView));
+ System.out.println("EAGL: EAGLLayer 0x"+Long.toHexString(caeaglLayer));
+ System.out.println("isUIWindow "+IOSUtil.isUIWindow(uiWindow)+", isUIView "+IOSUtil.isUIView(uiView)+
+ ", isCAEAGLLayer "+IOSUtil.isCAEAGLLayer(caeaglLayer));
+ final AbstractGraphicsScreen aScreen = NativeWindowFactory.createScreen(NativeWindowFactory.createDevice(null, true /* own */), -1);
+ final UpstreamWindowHookMutableSizePos hook = new UpstreamWindowHookMutableSizePos(0, 0, width, height, width, height);
+ final MutableGraphicsConfiguration config = new MutableGraphicsConfiguration(aScreen, reqCaps, reqCaps);
+ final WrappedWindow nativeWindow = new WrappedWindow(config, uiView, hook, true, uiWindow);
+
+ // 3) Create a GLDrawable ..
+ final GLDrawable drawable = factory.createGLDrawable(nativeWindow);
+ drawable.setRealized(true);
+ // final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(aScreen.getDevice(), reqCaps, null, width, height);
+ glad = new GLAutoDrawableDelegate(drawable, null, nativeWindow, false, null) {
+ @Override
+ protected void destroyImplInLock() {
+ super.destroyImplInLock(); // destroys drawable/context
+ nativeWindow.destroy(); // destroys the actual window, incl. the device
+ IOSUtil.DestroyUIWindow(uiWindow);
+ }
+ };
+ glad.display(); // force native context creation
+
+ // Check caps of GLDrawable after realization
+ final GLCapabilitiesImmutable chosenCaps = glad.getChosenGLCapabilities();
+ System.out.println("Choosen GL Caps: "+chosenCaps);
+
+ GLEventListener demo = null;
+ {
+ try {
+ demo = (GLEventListener) ReflectionUtil.createInstance(demoName, Hello.class.getClassLoader());
+ } catch( final Exception e ) {
+ System.err.println(e.getMessage()+" using: <"+demoName+">");
+ }
+ if( null == demo ) {
+ demo = new RedSquareES2();
+ }
+ }
+ System.out.println("Choosen demo "+demo.getClass().getName());
+ glad.addGLEventListener(demo);
+
+ for(int i=0; i<60*10; i++) { // 10s w/ 60fps
+ glad.display(); // force native context creation
+ try {
+ Thread.sleep(16);
+ } catch (final InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ } finally {
+ if( null != glad ) {
+ glad.destroy();
+ }
+ }
+
+ System.err.println("");
+ System.err.println("mark-05");
+ System.err.println("");
+
+ if( exitJVM ) {
+ System.exit(0);
+ }
+ }
+}
diff --git a/src/demos/com/jogamp/opengl/demos/ios/Hello0.java b/src/demos/com/jogamp/opengl/demos/ios/Hello0.java
new file mode 100644
index 000000000..045914855
--- /dev/null
+++ b/src/demos/com/jogamp/opengl/demos/ios/Hello0.java
@@ -0,0 +1,20 @@
+package com.jogamp.opengl.demos.ios;
+
+import com.jogamp.opengl.GLProfile;
+
+import jogamp.nativewindow.ios.IOSUtil;
+
+public class Hello0 {
+ public static void main(final String[] args) {
+ System.out.println("Hello JogAmp World");
+ GLProfile.initSingleton();
+ {
+ IOSUtil.RunOnMainThread(true, false, new Runnable() {
+ @Override
+ public void run() {
+ IOSUtil.CreateGLViewDemoA();
+ } } );
+ }
+ }
+
+}