JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLDebug00NEWT.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.GL;
34import com.jogamp.opengl.GL2ES2;
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLContext;
37import com.jogamp.opengl.GLDebugListener;
38import com.jogamp.opengl.GLDebugMessage;
39import com.jogamp.opengl.GLDrawable;
40import com.jogamp.opengl.GLDrawableFactory;
41import com.jogamp.opengl.GLProfile;
42
43import org.junit.Assert;
44import org.junit.Test;
45import org.junit.FixMethodOrder;
46import org.junit.runners.MethodSorters;
47
48import com.jogamp.newt.Display;
49import com.jogamp.newt.NewtFactory;
50import com.jogamp.newt.Screen;
51import com.jogamp.newt.Window;
52import com.jogamp.opengl.test.junit.util.UITestCase;
53
54@FixMethodOrder(MethodSorters.NAME_ASCENDING)
55public class TestGLDebug00NEWT extends UITestCase {
56
57 static String dbgTstMsg0 = "Hello World";
58 static int dbgTstId0 = 42;
59
60 static GLProfile getGLProfile(final String profile) {
61 if( !GLProfile.isAvailable(profile) ) {
62 System.err.println("Profile "+profile+" n/a");
63 return null;
64 }
65 return GLProfile.get(profile);
66 }
67
68 public static class WindowContext {
69 public final Window window;
70 public final GLContext context;
71
72 public WindowContext(final Window w, final GLContext c) {
73 window = w;
74 context = c;
75 }
76 }
77
78 WindowContext createWindow(final GLProfile glp, final boolean debugGL) {
79 final GLCapabilities caps = new GLCapabilities(glp);
80 //
81 // Create native windowing resources .. X11/Win/OSX
82 //
83 final Display display = NewtFactory.createDisplay(null); // local display
84 Assert.assertNotNull(display);
85
86 final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
87 Assert.assertNotNull(screen);
88
89 final Window window = NewtFactory.createWindow(screen, caps);
90 Assert.assertNotNull(window);
91 window.setSize(128, 128);
92 window.setVisible(true);
93
95 final GLDrawable drawable = factory.createGLDrawable(window);
96 Assert.assertNotNull(drawable);
97
98 drawable.setRealized(true);
99
100 final GLContext context = drawable.createContext(null);
101 Assert.assertNotNull(context);
102
103 context.enableGLDebugMessage(debugGL);
104
105 final int res = context.makeCurrent();
106 Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res);
107
108 return new WindowContext(window, context);
109 }
110
111 void destroyWindow(final WindowContext winctx) {
112 final GLDrawable drawable = winctx.context.getGLDrawable();
113
114 Assert.assertNotNull(winctx.context);
115 winctx.context.destroy();
116
117 Assert.assertNotNull(drawable);
118 drawable.setRealized(false);
119
120 Assert.assertNotNull(winctx.window);
121 winctx.window.destroy();
122 }
123
124
125 void testX1GLDebugEnableDisable(final GLProfile glp, final boolean enable) throws InterruptedException {
126 final WindowContext winctx = createWindow(glp, enable);
127 final String glDebugExt = winctx.context.getGLDebugMessageExtension();
128 System.err.println("glDebug extension: "+glDebugExt);
129 System.err.println("glDebug enabled: "+winctx.context.isGLDebugMessageEnabled());
130 System.err.println("glDebug sync: "+winctx.context.isGLDebugSynchronous());
131 System.err.println("context version: "+winctx.context.getGLVersion());
132
133 Assert.assertEquals((null == glDebugExt) ? false : enable, winctx.context.isGLDebugMessageEnabled());
134
135 destroyWindow(winctx);
136 }
137
138 @Test
139 public void test01GL2GL3DebugDisabled() throws InterruptedException {
140 final GLProfile glp = getGLProfile(GLProfile.GL2GL3);
141 if( null == glp ) {
142 return;
143 }
144 testX1GLDebugEnableDisable(glp, false);
145 }
146
147 @Test
148 public void test02GL2GL3DebugEnabled() throws InterruptedException {
149 final GLProfile glp = getGLProfile(GLProfile.GL2GL3);
150 if( null == glp ) {
151 return;
152 }
153 testX1GLDebugEnableDisable(glp, true);
154 }
155
156 @Test
157 public void test11GLES2DebugDisabled() throws InterruptedException {
158 final GLProfile glp = getGLProfile(GLProfile.GLES2);
159 if( null == glp ) {
160 return;
161 }
162 testX1GLDebugEnableDisable(glp, false);
163 }
164
165 @Test
166 public void test12GLES2DebugEnabled() throws InterruptedException {
167 final GLProfile glp = getGLProfile(GLProfile.GLES2);
168 if( null == glp ) {
169 return;
170 }
171 testX1GLDebugEnableDisable(glp, true);
172 }
173
174 void testX2GLDebugError(final GLProfile glp) throws InterruptedException {
175 final WindowContext winctx = createWindow(glp, true);
176
177 final MyGLDebugListener myGLDebugListener = new MyGLDebugListener(
181 winctx.context.addGLDebugListener(myGLDebugListener);
182
183 final GL gl = winctx.context.getGL();
184
185 gl.glBindFramebuffer(-1, -1); // ERROR !
186
187 if( winctx.context.isGLDebugMessageEnabled() ) {
188 Assert.assertEquals(true, myGLDebugListener.received());
189 }
190
191 destroyWindow(winctx);
192 }
193
194 @Test
195 public void test03GL2GL3DebugError() throws InterruptedException {
196 final GLProfile glp = getGLProfile(GLProfile.GL2GL3);
197 if( null == glp ) {
198 return;
199 }
200 testX2GLDebugError(glp);
201 }
202
203 @Test
204 public void test13GLES2DebugError() throws InterruptedException {
205 final GLProfile glp = getGLProfile(GLProfile.GLES2);
206 if( null == glp ) {
207 return;
208 }
209 testX2GLDebugError(glp);
210 }
211
212 void testX3GLDebugInsert(final GLProfile glp) throws InterruptedException {
213 final WindowContext winctx = createWindow(glp, true);
214 final MyGLDebugListener myGLDebugListener = new MyGLDebugListener(dbgTstMsg0, dbgTstId0);
215 winctx.context.addGLDebugListener(myGLDebugListener);
216
217 final String glDebugExt = winctx.context.getGLDebugMessageExtension();
218 Assert.assertEquals((null == glDebugExt) ? false : true, winctx.context.isGLDebugMessageEnabled());
219
220 if( winctx.context.isGLDebugMessageEnabled() ) {
221 winctx.context.glDebugMessageInsert(GL2ES2.GL_DEBUG_SOURCE_APPLICATION,
223 dbgTstId0,
224 GL2ES2.GL_DEBUG_SEVERITY_MEDIUM, dbgTstMsg0);
225 Assert.assertEquals(true, myGLDebugListener.received());
226 }
227
228 destroyWindow(winctx);
229 }
230
231 @Test
232 public void test04GL2GL3DebugInsert() throws InterruptedException {
233 final GLProfile glp = getGLProfile(GLProfile.GL2GL3);
234 if( null == glp ) {
235 return;
236 }
237 testX3GLDebugInsert(glp);
238 }
239
240 @Test
241 public void test14GLES2DebugInsert() throws InterruptedException {
242 final GLProfile glp = getGLProfile(GLProfile.GLES2);
243 if( null == glp ) {
244 return;
245 }
246 testX3GLDebugInsert(glp);
247 }
248
249 public static void main(final String args[]) throws IOException {
250 final String tstname = TestGLDebug00NEWT.class.getName();
251 org.junit.runner.JUnitCore.main(tstname);
252 }
253
254 public static class MyGLDebugListener implements GLDebugListener {
255 int recSource;
256 int recType;
257 int recSeverity;
258
259 String recMsg;
260 int recId;
261 boolean received = false;
262
263 public MyGLDebugListener(final int recSource, final int recType, final int recSeverity) {
264 this.recSource = recSource;
265 this.recType = recType;
266 this.recSeverity = recSeverity;
267 this.recMsg = null;
268 this.recId = -1;
269
270 }
271 public MyGLDebugListener(final String recMsg, final int recId) {
272 this.recSource = -1;
273 this.recType = -1;
274 this.recSeverity = -1;
275 this.recMsg = recMsg;
276 this.recId = recId;
277 }
278
279 public boolean received() { return received; }
280
281 public void messageSent(final GLDebugMessage event) {
282 System.err.println("XXX: "+event);
283 if(null != recMsg && recMsg.equals(event.getDbgMsg()) && recId == event.getDbgId()) {
284 received = true;
285 } else if(0 <= recSource && recSource == event.getDbgSource() &&
286 recType == event.getDbgType() &&
287 recSeverity== event.getDbgSeverity() ) {
288 received = true;
289 }
290 // Thread.dumpStack();
291 }
292 }
293}
294
static Display createDisplay(final String name)
Create a Display entity.
static Window createWindow(final CapabilitiesImmutable caps)
Create a top level Window entity on the default Display and default Screen.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
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.
static final int CONTEXT_CURRENT
Indicates that the context was made current during the last call to makeCurrent, value {@value}.
Definition: GLContext.java:114
abstract void enableGLDebugMessage(boolean enable)
Enables or disables the GLDebugOutput feature of extension GLExtensions#ARB_debug_output or GLExtensi...
static final int CONTEXT_CURRENT_NEW
Indicates that a newly-created context was made current during the last call to makeCurrent,...
Definition: GLContext.java:116
OpenGL debug message generated by the driver and delivered via GLDebugListener.
abstract GLDrawable createGLDrawable(NativeSurface target)
Returns an unrealized GLDrawable according to it's chosen GLCapabilitiesImmutable,...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
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.
void messageSent(final GLDebugMessage event)
Handle GLDebugMessage message sent from native GL implementation.
MyGLDebugListener(final int recSource, final int recType, final int recSeverity)
Specifying NEWT's Window functionality:
Definition: Window.java:115
void setSize(int width, int height)
Sets the size of the window's client area in window units, excluding decorations.
void setVisible(boolean visible)
Calls setVisible(true, visible), i.e.
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
GL getGL()
Casts this object to the GL interface.
Listener for GLDebugMessages.
An abstraction for an OpenGL rendering target.
Definition: GLDrawable.java:51
void setRealized(boolean realized)
Indicates to GLDrawable implementations whether the underlying surface has been created and can be dr...
GLContext createContext(GLContext shareWith)
Creates a new context for drawing to this drawable that will optionally share buffer objects,...
void glBindFramebuffer(int target, int framebuffer)
Entry point to C language function: void {@native glBindFramebuffer}(GLenum target,...