JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLDebug01NEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 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.acore;
30
31import java.io.IOException;
32
33import com.jogamp.opengl.GL2ES2;
34import com.jogamp.opengl.GLAutoDrawable;
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLContext;
37import com.jogamp.opengl.GLDebugListener;
38import com.jogamp.opengl.GLDebugMessage;
39import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.GLRunnable;
41
42import org.junit.Assert;
43import org.junit.Test;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
46
47import com.jogamp.newt.opengl.GLWindow;
48import com.jogamp.opengl.test.junit.util.UITestCase;
49
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
51public class TestGLDebug01NEWT extends UITestCase {
52
53 static String dbgTstMsg0 = "Hello World";
54 static int dbgTstId0 = 42;
55
56 static GLProfile getGLProfile(final String profile) {
57 if( !GLProfile.isAvailable(profile) ) {
58 System.err.println("Profile "+profile+" n/a");
59 return null;
60 }
61 return GLProfile.get(profile);
62 }
63
64 GLWindow createWindow(final GLProfile glp, final boolean debugGL) {
65 final GLCapabilities caps = new GLCapabilities(glp);
66 //
67 // Create native windowing resources .. X11/Win/OSX
68 //
69 final GLWindow window = GLWindow.create(caps);
70 Assert.assertNotNull(window);
72 window.setSize(128, 128);
73 window.setVisible(true);
74
75 Assert.assertNotNull(window.getContext());
76 Assert.assertNotNull(window.getContext().isCreated());
77
78 return window;
79 }
80
81 void destroyWindow(final GLWindow window) {
82 window.destroy();
83 }
84
85
86 void testX1GLDebugEnableDisable(final GLProfile glp, final boolean enable, final String dbgTstMsg, final int dbgTstId) throws InterruptedException {
87 final GLWindow window = createWindow(glp, enable);
88 final GLContext ctx = window.getContext();
89 final MyGLDebugListener myGLDebugListener = new MyGLDebugListener(dbgTstMsg, dbgTstId);
90 if(enable) {
91 ctx.addGLDebugListener(myGLDebugListener);
92 }
93 final String glDebugExt = ctx.getGLDebugMessageExtension();
94 System.err.println("glDebug extension: "+glDebugExt);
95 System.err.println("glDebug enabled: "+ctx.isGLDebugMessageEnabled());
96 System.err.println("glDebug sync: "+ ctx.isGLDebugSynchronous());
97 System.err.println("context version: "+ctx.getGLVersion());
98
99 Assert.assertEquals((null == glDebugExt) ? false : enable, ctx.isGLDebugMessageEnabled());
100 if(ctx.isGLDebugMessageEnabled() && null != dbgTstMsg && 0 <= dbgTstId) {
101 window.invoke(true, new GLRunnable() {
102 public boolean run(final GLAutoDrawable drawable) {
105 dbgTstId,
107 return true;
108 }
109 });
110 Assert.assertEquals(true, myGLDebugListener.received());
111 }
112
113 destroyWindow(window);
114 }
115
116 @Test
117 public void test01GL2GL3DebugDisabled() throws InterruptedException {
118 final GLProfile glp = getGLProfile(GLProfile.GL2GL3);
119 if( null == glp ) {
120 return;
121 }
122 testX1GLDebugEnableDisable(glp, false, null, -1);
123 }
124
125 @Test
126 public void test02GL2GL3DebugEnabled() throws InterruptedException {
127 final GLProfile glp = getGLProfile(GLProfile.GL2GL3);
128 if( null == glp ) {
129 return;
130 }
131 testX1GLDebugEnableDisable(glp, true, dbgTstMsg0, dbgTstId0);
132 }
133
134 @Test
135 public void test11GLES2DebugDisabled() throws InterruptedException {
136 final GLProfile glp = getGLProfile(GLProfile.GLES2);
137 if( null == glp ) {
138 return;
139 }
140 testX1GLDebugEnableDisable(glp, false, null, -1);
141 }
142
143 @Test
144 public void test12GLES2DebugEnabled() throws InterruptedException {
145 final GLProfile glp = getGLProfile(GLProfile.GLES2);
146 if( null == glp ) {
147 return;
148 }
149 testX1GLDebugEnableDisable(glp, true, dbgTstMsg0, dbgTstId0);
150 }
151
152 void testX3GLDebugError(final GLProfile glp) throws InterruptedException {
153 final GLWindow window = createWindow(glp, true);
154
155 final MyGLDebugListener myGLDebugListener = new MyGLDebugListener(
159 window.getContext().addGLDebugListener(myGLDebugListener);
160
161 window.invoke(true, new GLRunnable() {
162 public boolean run(final GLAutoDrawable drawable) {
163 drawable.getGL().glBindFramebuffer(-1, -1); // ERROR !
164 return true;
165 }
166 } );
167
168 if( window.getContext().isGLDebugMessageEnabled() ) {
169 Assert.assertEquals(true, myGLDebugListener.received());
170 }
171
172 destroyWindow(window);
173 }
174
175 @Test
176 public void test03GL2GL3DebugError() throws InterruptedException {
177 final GLProfile glp = getGLProfile(GLProfile.GL2GL3);
178 if( null == glp ) {
179 return;
180 }
181 testX3GLDebugError(glp);
182 }
183
184 @Test
185 public void test13GLES2DebugError() throws InterruptedException {
186 final GLProfile glp = getGLProfile(GLProfile.GLES2);
187 if( null == glp ) {
188 return;
189 }
190 testX3GLDebugError(glp);
191 }
192
193 public static void main(final String args[]) throws IOException {
194 final String tstname = TestGLDebug01NEWT.class.getName();
195 org.junit.runner.JUnitCore.main(tstname);
196 }
197
198 public static class MyGLDebugListener implements GLDebugListener {
199 int recSource;
200 int recType;
201 int recSeverity;
202
203 String recMsg;
204 int recId;
205 boolean received = false;
206
207 public MyGLDebugListener(final int recSource, final int recType, final int recSeverity) {
208 this.recSource = recSource;
209 this.recType = recType;
210 this.recSeverity = recSeverity;
211 this.recMsg = null;
212 this.recId = -1;
213
214 }
215 public MyGLDebugListener(final String recMsg, final int recId) {
216 this.recSource = -1;
217 this.recType = -1;
218 this.recSeverity = -1;
219 this.recMsg = recMsg;
220 this.recId = recId;
221 }
222
223 public boolean received() { return received; }
224
225 public void messageSent(final GLDebugMessage event) {
226 System.err.println("XXX: "+event);
227 if(null != recMsg && recMsg.equals(event.getDbgMsg()) && recId == event.getDbgId()) {
228 received = true;
229 } else if(0 <= recSource && recSource == event.getDbgSource() &&
230 recType == event.getDbgType() &&
231 recSeverity== event.getDbgSeverity() ) {
232 received = true;
233 }
234 // Thread.dumpStack();
235 }
236 }
237}
238
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
final boolean isCreated()
Indicates whether the underlying native OpenGL context has been created.
Definition: GLContext.java:604
abstract boolean isGLDebugMessageEnabled()
abstract boolean isGLDebugSynchronous()
abstract void addGLDebugListener(GLDebugListener listener)
Add GLDebugListener.
abstract String getGLDebugMessageExtension()
static final int CTX_OPTION_DEBUG
ARB_create_context related: flag debug.
Definition: GLContext.java:180
final String getGLVersion()
Returns a valid OpenGL version string, ie
Definition: GLContext.java:769
abstract void glDebugMessageInsert(int source, int type, int id, int severity, String buf)
Generic entry for GL2GL3#glDebugMessageInsert(int, int, int, int, int, String) and GL2GL3#glDebugMess...
OpenGL debug message generated by the driver and delivered via GLDebugListener.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
static final String GLES2
The embedded OpenGL profile ES 2.x, with x >= 0.
Definition: GLProfile.java:585
static final String GL2GL3
The intersection of the desktop GL3 and GL2 profile.
Definition: GLProfile.java:597
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
MyGLDebugListener(final int recSource, final int recType, final int recSeverity)
void messageSent(final GLDebugMessage event)
Handle GLDebugMessage message sent from native GL implementation.
static final int GL_DEBUG_SOURCE_APPLICATION
GL_KHR_debug, GL_ES_VERSION_3_2, GL_VERSION_4_3, GL_KHR_debug, GL_ARB_debug_output Alias for: GL_DEBU...
Definition: GL2ES2.java:550
static final int GL_DEBUG_TYPE_OTHER
GL_KHR_debug, GL_ES_VERSION_3_2, GL_VERSION_4_3, GL_ARB_debug_output, GL_KHR_debug Alias for: GL_DEBU...
Definition: GL2ES2.java:262
static final int GL_DEBUG_TYPE_ERROR
GL_KHR_debug, GL_ES_VERSION_3_2, GL_VERSION_4_3, GL_ARB_debug_output, GL_KHR_debug Alias for: GL_DEBU...
Definition: GL2ES2.java:333
static final int GL_DEBUG_SEVERITY_MEDIUM
GL_KHR_debug, GL_ES_VERSION_3_2, GL_VERSION_4_3, GL_KHR_debug, GL_ARB_debug_output,...
Definition: GL2ES2.java:576
static final int GL_DEBUG_SEVERITY_HIGH
GL_KHR_debug, GL_ES_VERSION_3_2, GL_VERSION_4_3, GL_ARB_debug_output, GL_KHR_debug,...
Definition: GL2ES2.java:187
static final int GL_DEBUG_SOURCE_API
GL_KHR_debug, GL_ES_VERSION_3_2, GL_VERSION_4_3, GL_ARB_debug_output, GL_KHR_debug Alias for: GL_DEBU...
Definition: GL2ES2.java:190
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void setContextCreationFlags(int flags)
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GLContext getContext()
Returns the context associated with this drawable.
Listener for GLDebugMessages.
void glBindFramebuffer(int target, int framebuffer)
Entry point to C language function: void {@native glBindFramebuffer}(GLenum target,...