aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPointsNEWT.java138
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/PointsDemo.java48
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/PointsDemoES1.java155
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java207
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp40
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp42
6 files changed, 630 insertions, 0 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPointsNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPointsNEWT.java
new file mode 100644
index 000000000..37994914e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPointsNEWT.java
@@ -0,0 +1,138 @@
+/**
+ * Copyright 2011 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.test.junit.jogl.acore;
+
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+import com.jogamp.opengl.test.junit.jogl.demos.PointsDemo;
+import com.jogamp.opengl.test.junit.jogl.demos.es1.PointsDemoES1;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.PointsDemoES2;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestPointsNEWT extends UITestCase {
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ width = 512;
+ height = 512;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL0(GLCapabilities caps, PointsDemo demo) throws InterruptedException {
+ GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle(getSimpleTestName("."));
+
+ glWindow.addGLEventListener(demo);
+ final SnapshotGLEventListener snap = new SnapshotGLEventListener();
+ snap.setPostSNDetail(demo.getClass().getSimpleName());
+ glWindow.addGLEventListener(snap);
+
+ glWindow.setSize(width, height);
+ glWindow.setVisible(true);
+
+ demo.setSmoothPoints(false);
+ snap.setMakeSnapshot();
+ snap.setPostSNDetail("flat");
+ glWindow.display();
+
+ demo.setSmoothPoints(true);
+ snap.setMakeSnapshot();
+ snap.setPostSNDetail("smooth");
+ glWindow.display();
+
+ demo.setPointParams(2f, 40f, 0.01f, 0.0f, 0.01f, 1f);
+ snap.setMakeSnapshot();
+ snap.setPostSNDetail("attn0");
+ glWindow.display();
+
+ glWindow.removeGLEventListener(demo);
+
+ glWindow.destroy();
+ }
+
+ protected void runTestGL(GLCapabilities caps, PointsDemo demo, boolean forceFFPEmu) throws InterruptedException {
+ // final PointsDemoES2 demo01 = new PointsDemoES2();
+ runTestGL0(caps, demo);
+ }
+
+ @Test
+ public void test01FFP__GL2() throws InterruptedException {
+ if(!GLProfile.isAvailable(GLProfile.GL2)) { System.err.println("GL2 n/a"); return; }
+ GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
+ runTestGL(caps, new PointsDemoES1(), false);
+ }
+
+ @Test
+ public void test02FFP__ES1() throws InterruptedException {
+ if(!GLProfile.isAvailable(GLProfile.GLES1)) { System.err.println("GLES1 n/a"); return; }
+ GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES1));
+ runTestGL(caps, new PointsDemoES1(), false);
+ }
+
+ @Test
+ public void test11GLSL_GL2() throws InterruptedException {
+ if(!GLProfile.isAvailable(GLProfile.GL2)) { System.err.println("GL2 n/a"); return; }
+ GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
+ runTestGL(caps, new PointsDemoES2(), false);
+ }
+
+ @Test
+ public void test12GLSL_ES2() throws InterruptedException {
+ if(!GLProfile.isAvailable(GLProfile.GLES2)) { System.err.println("GLES2 n/a"); return; }
+ GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2));
+ runTestGL(caps, new PointsDemoES2(), false); // should be FFPEmu implicit
+ }
+
+ static long duration = 1000; // ms
+
+ public static void main(String args[]) {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ org.junit.runner.JUnitCore.main(TestPointsNEWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/PointsDemo.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/PointsDemo.java
new file mode 100644
index 000000000..4f2e4153e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/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.test.junit.jogl.demos;
+
+import javax.media.opengl.GLEventListener;
+
+public abstract class PointsDemo implements GLEventListener {
+ int swapInterval = 0;
+ final int edge = 8; // 8*8
+
+ public PointsDemo(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/test/com/jogamp/opengl/test/junit/jogl/demos/es1/PointsDemoES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/PointsDemoES1.java
new file mode 100644
index 000000000..bfc2e94fe
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/PointsDemoES1.java
@@ -0,0 +1,155 @@
+/**
+ * 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.test.junit.jogl.demos.es1;
+
+import java.nio.FloatBuffer;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.test.junit.jogl.demos.PointsDemo;
+import com.jogamp.opengl.util.GLArrayDataServer;
+import com.jogamp.opengl.util.PMVMatrix;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.glu.GLU;
+import javax.media.opengl.glu.gl2es1.GLUgl2es1;
+
+public class PointsDemoES1 extends PointsDemo {
+ final static GLU glu = new GLUgl2es1();
+ GLArrayDataServer vertices ;
+ float[] pointSizes ;
+ private int swapInterval = 0;
+ final int edge = 8; // 8*8
+ boolean smooth = false;
+
+ public PointsDemoES1(int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public PointsDemoES1() {
+ this.swapInterval = 1;
+ }
+
+ public void setSmoothPoints(boolean v) { smooth = v; }
+
+ public void init(GLAutoDrawable glad) {
+ GL2ES1 gl = glad.getGL().getGL2ES1();
+ 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 Profile: "+gl.getGLProfile());
+
+ // Allocate Vertex Array
+ vertices = GLArrayDataServer.createFixed(GL2ES1.GL_VERTEX_ARRAY, 3, GL.GL_FLOAT, false, edge*edge, GL.GL_STATIC_DRAW);
+ pointSizes = new float[edge*edge];
+ 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[(i*edge+j)] = p;
+ }
+ }
+ vertices.seal(gl, true);
+ vertices.enableBuffer(gl, false);
+
+ // OpenGL Render Settings
+ gl.glEnable(GL2ES1.GL_DEPTH_TEST);
+ }
+
+ public void setPointParams(float minSize, float maxSize, float distAttenConst, float distAttenLinear, float distAttenQuadratic, float fadeThreshold) {
+ pointMinSize = minSize;
+ pointMaxSize = maxSize;
+ pointFadeThreshold = fadeThreshold;
+ pointDistAtten.put(0, distAttenConst);
+ pointDistAtten.put(1, distAttenLinear);
+ pointDistAtten.put(2, distAttenQuadratic);
+ }
+
+ /** default values */
+ private float pointMinSize = 0.0f;
+ private float pointMaxSize = 4096.0f;
+ private float pointFadeThreshold = 1.0f;
+ private final FloatBuffer pointDistAtten = Buffers.newDirectFloatBuffer(new float[] { 1.0f, 0.0f, 0.0f });
+
+ public void display(GLAutoDrawable glad) {
+ GL2ES1 gl = glad.getGL().getGL2ES1();
+ gl.glClearColor(0f, 0f, 0f, 0f);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
+ gl.glMatrixMode(GL2ES1.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0, 0, -10);
+
+ gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f );
+
+ vertices.enableBuffer(gl, true);
+
+ gl.glEnable ( GL.GL_BLEND );
+ gl.glBlendFunc ( GL.GL_SRC_ALPHA, GL.GL_ONE );
+ if(smooth) {
+ gl.glEnable(GL2ES1.GL_POINT_SMOOTH);
+ } else {
+ gl.glDisable(GL2ES1.GL_POINT_SMOOTH);
+ }
+ gl.glPointParameterf(GL2ES1.GL_POINT_SIZE_MIN, pointMinSize );
+ gl.glPointParameterf(GL2ES1.GL_POINT_SIZE_MAX, pointMaxSize );
+ gl.glPointParameterf(GL2ES1.GL_POINT_FADE_THRESHOLD_SIZE, pointFadeThreshold);
+ gl.glPointParameterfv(GL2ES1.GL_POINT_DISTANCE_ATTENUATION, pointDistAtten );
+
+ for(int i=edge*edge-1; i>=0; i--) {
+ gl.glPointSize(pointSizes[i]);
+ gl.glDrawArrays(GL.GL_POINTS, i, 1);
+ }
+
+ vertices.enableBuffer(gl, false);
+ }
+
+ public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
+ // Thread.dumpStack();
+ GL2ES1 gl = glad.getGL().getGL2ES1();
+
+ if(-1 != swapInterval) {
+ gl.setSwapInterval(swapInterval); // in case switching the drawable (impl. may bound attribute there)
+ }
+
+ // Set location in front of camera
+ gl.glMatrixMode(PMVMatrix.GL_PROJECTION);
+ gl.glLoadIdentity();
+ glu.gluPerspective(45.0F, ( (float) width / (float) height ) / 1.0f, 1.0F, 100.0F);
+ //gl.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
+ }
+
+ public void dispose(GLAutoDrawable glad) {
+ GL2ES1 gl = glad.getGL().getGL2ES1();
+ vertices.destroy(gl);
+ vertices = null;
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java
new file mode 100644
index 000000000..8c6d7e180
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/PointsDemoES2.java
@@ -0,0 +1,207 @@
+/**
+ * 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.test.junit.jogl.demos.es2;
+
+import java.nio.FloatBuffer;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.test.junit.jogl.demos.PointsDemo;
+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 javax.media.opengl.GL;
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLUniformData;
+
+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(int swapInterval) {
+ this.swapInterval = swapInterval;
+ }
+
+ public PointsDemoES2() {
+ this.swapInterval = 1;
+ }
+
+ public void setSmoothPoints(boolean v) {
+ pointParams.put(1, v ? 1.0f : 0.0f);
+ }
+
+ public void setPointParams(float minSize, float maxSize, float distAttenConst, float distAttenLinear, float distAttenQuadratic, 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(GLAutoDrawable glad) {
+ 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: "+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", false);
+ final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(), "shader",
+ "shader/bin", "PointsShader", false);
+ 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(PMVMatrix.GL_PROJECTION);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glMatrixMode(PMVMatrix.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(GL2ES2.GL_DEPTH_TEST);
+ st.useProgram(gl, false);
+ }
+
+ public void display(GLAutoDrawable glad) {
+ 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(PMVMatrix.GL_MODELVIEW);
+ pmvMatrix.glLoadIdentity();
+ pmvMatrix.glTranslatef(0, 0, -10);
+ st.uniform(gl, pmvMatrixUniform);
+
+ 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(GLAutoDrawable glad, int x, int y, int width, int height) {
+ // Thread.dumpStack();
+ GL2ES2 gl = glad.getGL().getGL2ES2();
+
+ if(-1 != swapInterval) {
+ 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(PMVMatrix.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(GLAutoDrawable glad) {
+ GL2ES2 gl = glad.getGL().getGL2ES2();
+ st.destroy(gl);
+ st = null;
+ pmvMatrix.destroy();
+ pmvMatrix = null;
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp
new file mode 100644
index 000000000..3e3be10b3
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.fp
@@ -0,0 +1,40 @@
+
+// [0].rgba: 0, smooth, attnMinSz, attnMaxSz
+// [1].rgba: attnCoeff(3), attnFadeTs
+uniform vec4 mgl_PointParams[2];
+
+#define pointSmooth (mgl_PointParams[0].g)
+
+varying vec4 frontColor;
+
+// #define TEST 1
+
+void main (void)
+{
+ gl_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
+ gl_FragColor.a *= r1;
+ #else
+ gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
+ gl_FragColor.r = r1 < 0.0 ? 1.0 : 0.0;
+ gl_FragColor.g = r > 1.0 ? 1.0 : 0.0;
+ gl_FragColor.b = r > border ? 1.0 : 0.0;
+ #endif
+ }
+}
+
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp
new file mode 100644
index 000000000..5043a652b
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/PointsShader.vp
@@ -0,0 +1,42 @@
+
+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 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;
+}
+