JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLSLSimple01NEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.glsl;
30
31import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
32import com.jogamp.opengl.test.junit.util.GLSLSimpleProgram;
33import com.jogamp.opengl.test.junit.util.UITestCase;
34
35
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLContext;
38import com.jogamp.opengl.GLProfile;
39
40import org.junit.Assert;
41import org.junit.Test;
42import org.junit.FixMethodOrder;
43import org.junit.runners.MethodSorters;
44
45import com.jogamp.newt.opengl.GLWindow;
46import com.jogamp.opengl.util.Animator;
47import com.jogamp.opengl.test.junit.jogl.demos.es2.shader.RedSquareShader;
48import com.jogamp.opengl.test.junit.util.MiscUtils;
49
50import java.io.IOException;
51import com.jogamp.opengl.GL2ES2;
52
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54public class TestGLSLSimple01NEWT extends UITestCase {
55 static long durationPerTest = 100; // ms
56
57 @Test(timeout=60000)
58 public void testGLSLCompilation01() {
60 Assert.assertNotNull(glp);
61 final GLCapabilities caps = new GLCapabilities(glp);
62 Assert.assertNotNull(caps);
63
64 final GLWindow window = GLWindow.create(caps);
65 Assert.assertNotNull(window);
66 window.setSize(800, 600);
67 window.setVisible(true);
68 Assert.assertTrue(window.isNativeValid());
69
70 final GLContext context = window.getContext();
71
72 // trigger native creation of drawable/context
73 window.display();
74 Assert.assertTrue(window.isRealized());
75 Assert.assertTrue(window.getContext().isCreated());
76
77 context.makeCurrent();
78
79 // given
80
81 final GL2ES2 gl = context.getGL().getGL2ES2();
82 final GLSLSimpleProgram myShader = GLSLSimpleProgram.create(gl,
85 true);
86
87 myShader.release(gl);
88 context.release();
89 window.destroy();
90 }
91
92 @Test(timeout=60000)
93 public void testGLSLUse01() throws InterruptedException {
95 Assert.assertNotNull(glp);
96 final GLCapabilities caps = new GLCapabilities(glp);
97 Assert.assertNotNull(caps);
98
99 final GLWindow window = GLWindow.create(caps);
100 Assert.assertNotNull(window);
101 window.setSize(800, 600);
102 window.setVisible(true);
103 Assert.assertTrue(window.isNativeValid());
104 window.addGLEventListener(new RedSquareES2());
105
106 final Animator animator = new Animator(window);
107 animator.setUpdateFPSFrames(1, null);
108 animator.start();
109 Assert.assertEquals(true, animator.isAnimating());
110 while(animator.isAnimating() && animator.getTotalFPSDuration()<durationPerTest) {
111 Thread.sleep(100);
112 }
113 Assert.assertEquals(true, animator.isAnimating());
114
115 window.destroy();
116 animator.stop();
117 }
118
119 public static void main(final String args[]) throws IOException {
120 System.err.println("main - start");
121 for(int i=0; i<args.length; i++) {
122 if(args[i].equals("-time")) {
123 durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest);
124 }
125 }
126 final String tstname = TestGLSLSimple01NEWT.class.getName();
127 org.junit.runner.JUnitCore.main(tstname);
128 System.err.println("main - end");
129 }
130
131}
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
Abstraction for an OpenGL rendering context.
Definition: GLContext.java:74
abstract int makeCurrent()
Makes this GLContext current on the calling thread.
final boolean isCreated()
Indicates whether the underlying native OpenGL context has been created.
Definition: GLContext.java:604
abstract void release()
Releases control of this GLContext from the current thread.
abstract GL getGL()
Returns the GL pipeline object for this GLContext.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static GLSLSimpleProgram create(final GL2ES2 gl, final String vertShaderCode, final String fragShaderCode, final boolean link)
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GLContext getContext()
Returns the context associated with this drawable.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
boolean isRealized()
Returns true if this drawable is realized, otherwise false.