JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestShaderCompilationBug459AWT.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 */
28package com.jogamp.opengl.test.junit.jogl.glsl;
29
30import com.jogamp.opengl.test.junit.util.UITestCase;
31import com.jogamp.opengl.util.Animator;
32
33import com.jogamp.opengl.GL;
34import com.jogamp.opengl.GL2ES2;
35import com.jogamp.opengl.GL2GL3;
36import com.jogamp.opengl.GLAutoDrawable;
37import com.jogamp.opengl.GLCapabilities;
38import com.jogamp.opengl.GLEventListener;
39import com.jogamp.opengl.GLException;
40import com.jogamp.opengl.GLProfile;
41import com.jogamp.opengl.awt.GLCanvas;
42
43import java.awt.Frame;
44
45import org.junit.Assert;
46import org.junit.Assume;
47import org.junit.BeforeClass;
48import org.junit.AfterClass;
49import org.junit.Test;
50import org.junit.FixMethodOrder;
51import org.junit.runners.MethodSorters;
52
53/**
54 * Duplicates bug 459, where a vertex shader won't compile when 8 bits of stencil are requested.
55 * This bug is Windows-only; it works on Mac OS X and CentOS.
56 */
57@FixMethodOrder(MethodSorters.NAME_ASCENDING)
59 static int width, height;
60 static long duration = 500; // ms
61 /** Exception in shader code sets this, since it won't bubble up through AWT. */
62 GLException glexception;
63
64 @BeforeClass
65 public static void initClass() {
66 width = 512;
67 height = 512;
68 }
69
70 @AfterClass
71 public static void releaseClass() {
72 }
73
74 @Test
75 public void compileShader() throws InterruptedException {
77 final GLCapabilities caps = new GLCapabilities(glp);
78 // commenting out this line makes it work
79 caps.setStencilBits(8);
80
81 // commenting in this line also makes it work
82 //caps.setSampleBuffers(true);
83
84 final Frame frame = new Frame("Bug 459 shader compilation test");
85 Assert.assertNotNull(frame);
86
87 final GLCanvas glCanvas = new GLCanvas(caps);
88 Assert.assertNotNull(glCanvas);
89 frame.add(glCanvas);
90
91 glCanvas.addGLEventListener(new GLEventListener() {
92 /* @Override */
93 public void init(final GLAutoDrawable drawable) {
94 final String code = "void main(void){gl_Position = vec4(0,0,0,1);}";
95
96 final GL2GL3 gl = drawable.getGL().getGL2GL3();
97 final int id = gl.glCreateShader(GL2ES2.GL_VERTEX_SHADER);
98
99 try {
100 gl.glShaderSource(id, 1, new String[] { code }, (int[])null, 0);
101 gl.glCompileShader(id);
102
103 final int[] compiled = new int[1];
104 gl.glGetShaderiv(id, GL2ES2.GL_COMPILE_STATUS, compiled, 0);
105 if (compiled[0] == GL.GL_FALSE) {
106 final int[] logLength = new int[1];
107 gl.glGetShaderiv(id, GL2ES2.GL_INFO_LOG_LENGTH, logLength, 0);
108
109 final byte[] log = new byte[logLength[0]];
110 gl.glGetShaderInfoLog(id, logLength[0], (int[])null, 0, log, 0);
111
112 System.err.println("Error compiling the shader: " + new String(log));
113
114 gl.glDeleteShader(id);
115 }
116 else {
117 System.out.println("Shader compiled: id=" + id);
118 }
119 }
120 catch( final GLException e ) {
121 glexception = e;
122 }
123 }
124
125 /* @Override */
126 public void dispose(final GLAutoDrawable drawable) {
127 }
128
129 /* @Override */
130 public void display(final GLAutoDrawable drawable) {
131 }
132
133 /* @Override */
134 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
135 }
136 });
137
138 final Animator animator = new Animator(glCanvas);
139 try {
140 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
141 public void run() {
142 frame.setSize(512, 512);
143 frame.setVisible(true);
144 } } );
145 } catch(final Exception ex) {
146 throw new RuntimeException(ex);
147 }
148 animator.setUpdateFPSFrames(1, null);
149 animator.start();
150
151 while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
152 Thread.sleep(100);
153 }
154
155 Assert.assertTrue( glexception != null ? glexception.getMessage() : "", glexception == null );
156 Assert.assertNotNull(frame);
157 Assert.assertNotNull(glCanvas);
158 Assert.assertNotNull(animator);
159
160 animator.stop();
161 Assert.assertEquals(false, animator.isAnimating());
162 try {
163 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
164 public void run() {
165 frame.setVisible(false);
166 frame.remove(glCanvas);
167 frame.dispose();
168 }});
169 } catch( final Throwable throwable ) {
170 throwable.printStackTrace();
171 Assume.assumeNoException( throwable );
172 }
173 }
174
175 public static void main(final String args[]) {
176 org.junit.runner.JUnitCore.main(TestShaderCompilationBug459AWT.class.getName());
177 }
178}
Specifies a set of OpenGL capabilities.
void setStencilBits(final int stencilBits)
Sets the number of bits requested for the stencil buffer.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
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.
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
Duplicates bug 459, where a vertex shader won't compile when 8 bits of stencil are requested.
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
static final int GL_VERTEX_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_EXT_vertex_shader, GL_ARB_vertex_shader Alias for: GL_VERTEX_SH...
Definition: GL2ES2.java:39
void glCompileShader(int shader)
Entry point to C language function: void {@native glCompileShader}(GLuint shader) Part of GL_ES_VE...
void glDeleteShader(int shader)
Entry point to C language function: void {@native glDeleteShader}(GLuint shader) Part of GL_ES_VER...
static final int GL_COMPILE_STATUS
GL_ES_VERSION_2_0, GL_VERSION_2_0 Define "GL_COMPILE_STATUS" with expression '0x8B81',...
Definition: GL2ES2.java:72
void glGetShaderiv(int shader, int pname, IntBuffer params)
Entry point to C language function: void {@native glGetShaderiv}(GLuint shader, GLenum pname,...
void glShaderSource(int shader, int count, String[] string, IntBuffer length)
Entry point to C language function: void {@native glShaderSource}(GLuint shader, GLsizei count,...
int glCreateShader(int type)
Entry point to C language function: GLuint {@native glCreateShader}(GLenum type) Part of GL_ES_VER...
void glGetShaderInfoLog(int shader, int bufSize, IntBuffer length, ByteBuffer infoLog)
Entry point to C language function: void {@native glGetShaderInfoLog}(GLuint shader,...
static final int GL_INFO_LOG_LENGTH
GL_ES_VERSION_2_0, GL_VERSION_2_0 Define "GL_INFO_LOG_LENGTH" with expression '0x8B84',...
Definition: GL2ES2.java:379
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GL2GL3 getGL2GL3()
Casts this object to the GL2GL3 interface.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
static final int GL_FALSE
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FALSE" with expressio...
Definition: GL.java:251