JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTransformFeedbackVaryingsBug407NEWT.java
Go to the documentation of this file.
1package com.jogamp.opengl.test.junit.jogl.glsl;
2
3import com.jogamp.opengl.test.junit.util.NEWTGLContext;
4import com.jogamp.opengl.test.junit.util.UITestCase;
5
6import java.io.ByteArrayOutputStream;
7import java.io.PrintStream;
8
9import com.jogamp.opengl.GL;
10import com.jogamp.opengl.GL2ES2;
11import com.jogamp.opengl.GL2ES3;
12import com.jogamp.opengl.GL3;
13import com.jogamp.opengl.GLCapabilities;
14import com.jogamp.opengl.GLException;
15import com.jogamp.opengl.GLProfile;
16
17import org.junit.Assert;
18import org.junit.Test;
19import org.junit.FixMethodOrder;
20import org.junit.runners.MethodSorters;
21
22import com.jogamp.opengl.util.glsl.ShaderUtil;
23
24import java.io.IOException;
25
26/**
27 * Bug 'Function glTransformFeedbackVaryings incorrectly passes argument'
28 * http://jogamp.org/bugzilla/show_bug.cgi?id=407
29 */
30@FixMethodOrder(MethodSorters.NAME_ASCENDING)
32
33 private static final boolean debugGL = true;
34
35 private static final String VERTEX_SHADER_TEXT =
36 "#version 150 \n"
37 + " \n"
38 + "out vec4 Position; \n"
39 + " \n"
40 + "void main() { \n"
41 + " Position = vec4(1.0, 1.0, 1.0, 1.0); \n"
42 + "} \n";
43
44 static class MyShader {
45 int shaderProgram;
46 int vertShader;
47
48 MyShader(final int shaderProgram, final int vertShader) {
49 this.shaderProgram = shaderProgram;
50 this.vertShader = vertShader;
51 }
52 }
53
54 private MyShader attachShader(final GL3 gl, final String text, final int type) {
55 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
56 final PrintStream pbaos = new PrintStream(baos);
57
58 final int shaderProgram = gl.glCreateProgram();
59
60 final int vertShader = gl.glCreateShader(type);
61
62 final String[] lines = new String[]{text};
63 final int[] lengths = new int[]{lines[0].length()};
64 gl.glShaderSource(vertShader, lines.length, lines, lengths, 0);
65 gl.glCompileShader(vertShader);
66
67 if(!ShaderUtil.isShaderStatusValid(gl, vertShader, GL2ES2.GL_COMPILE_STATUS, pbaos)) {
68 System.out.println("getShader:postCompile: "+baos.toString());
69 Assert.assertTrue(false);
70 }
71 pbaos.flush(); baos.reset();
72
73 gl.glAttachShader(shaderProgram, vertShader);
74 Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
75
76 return new MyShader(shaderProgram, vertShader);
77 }
78
79 private void releaseShader(final GL3 gl, final MyShader myShader) {
80 if(null!=myShader) {
81 gl.glDetachShader(myShader.shaderProgram, myShader.vertShader);
82 gl.glDeleteShader(myShader.vertShader);
83 gl.glDeleteProgram(myShader.shaderProgram);
84 }
85 Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
86 }
87
88 final static String glps = GLProfile.GL3;
89
90 private NEWTGLContext.WindowContext prepareTest() throws GLException, InterruptedException {
91 final NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(
92 new GLCapabilities(GLProfile.getMaxProgrammable(true)), 480, 480, debugGL);
93 if(!winctx.context.getGL().isGL3()) {
94 System.err.println("GL3 not available");
95 cleanupTest(winctx);
96 return null;
97 }
98 Assert.assertEquals(GL.GL_NO_ERROR, winctx.context.getGL().glGetError());
99 return winctx;
100 }
101
102 private void cleanupTest(final NEWTGLContext.WindowContext winctx) {
103 if(null!=winctx) {
105 }
106 }
107
108 @Test(timeout=60000)
109 public void testGlTransformFeedbackVaryings_WhenVarNameOK() throws GLException, InterruptedException {
110 final NEWTGLContext.WindowContext winctx = prepareTest();
111 if(null == winctx) {
112 return;
113 }
114 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
115 final PrintStream pbaos = new PrintStream(baos);
116
117 // given
118
119 final GL3 gl = winctx.context.getGL().getGL3();
120 Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
121
122 final MyShader myShader = attachShader(gl, VERTEX_SHADER_TEXT, GL2ES2.GL_VERTEX_SHADER);
123 final String[] vars = new String[]{"Position"};
124
125 // when
126
127 gl.glTransformFeedbackVaryings(myShader.shaderProgram, 1, vars, GL2ES3.GL_SEPARATE_ATTRIBS);
128 gl.glLinkProgram(myShader.shaderProgram);
129 Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
130
131 // then
132
133 boolean error = false;
134
135 if(!ShaderUtil.isProgramLinkStatusValid(gl, myShader.shaderProgram, pbaos)) {
136 System.out.println("Error (unexpected link error) - testGlTransformFeedbackVaryings_WhenVarNameOK:postLink: "+baos.toString());
137 error = true;
138 }
139 pbaos.flush(); baos.reset();
140 Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
141
142 releaseShader(gl, myShader);
143 cleanupTest(winctx);
144 Assert.assertFalse(error);
145 }
146
147 @Test(timeout=60000)
148 public void testGlTransformFeedbackVaryings_WhenVarNameWrong() throws GLException, InterruptedException {
149 final NEWTGLContext.WindowContext winctx = prepareTest();
150 if(null == winctx) {
151 return;
152 }
153 final ByteArrayOutputStream baos = new ByteArrayOutputStream();
154 final PrintStream pbaos = new PrintStream(baos);
155
156 // given
157
158 final GL3 gl = winctx.context.getGL().getGL3();
159 Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
160
161 final MyShader myShader = attachShader(gl, VERTEX_SHADER_TEXT, GL2ES2.GL_VERTEX_SHADER);
162 final String[] vars = new String[]{"PPPosition"};
163
164 // when
165
166 gl.glTransformFeedbackVaryings(myShader.shaderProgram, 1, vars, GL2ES3.GL_SEPARATE_ATTRIBS);
167 gl.glLinkProgram(myShader.shaderProgram);
168
169 // then
170
171 boolean error = false;
172
173 if(!ShaderUtil.isProgramLinkStatusValid(gl, myShader.shaderProgram, pbaos)) {
174 System.out.println("GOOD (expected link error) - testGlTransformFeedbackVaryings_WhenVarNameWrong:postLink: "+baos.toString());
175 // should be invalid, due to wrong var name
176 } else {
177 // oops
178 System.out.println("Error (unexpected link success) - testGlTransformFeedbackVaryings_WhenVarNameWrong link worked, but it should not");
179 error = true;
180 }
181 pbaos.flush(); baos.reset();
182 Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
183
184 releaseShader(gl, myShader);
185 cleanupTest(winctx);
186
187 Assert.assertFalse(error);
188 }
189
190 public static void main(final String args[]) throws IOException {
191 final String tstname = TestTransformFeedbackVaryingsBug407NEWT.class.getName();
192 org.junit.runner.JUnitCore.main(tstname);
193 }
194
195}
Specifies a set of OpenGL capabilities.
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 GL3
The desktop OpenGL core profile 3.x, with x >= 1.
Definition: GLProfile.java:576
static GLProfile getMaxProgrammable(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the programmable shader pipeline.
Definition: GLProfile.java:831
Bug 'Function glTransformFeedbackVaryings incorrectly passes argument' http://jogamp....
static WindowContext createWindow(final GLCapabilities caps, final int width, final int height, final boolean debugGL)
static void destroyWindow(final WindowContext winctx)
static boolean isShaderStatusValid(final GL _gl, final int shaderObj, final int name, final PrintStream verboseOut)
Definition: ShaderUtil.java:76
static boolean isProgramLinkStatusValid(final GL _gl, final int programObj, final PrintStream verboseOut)
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...
void glDetachShader(int program, int shader)
Entry point to C language function: void {@native glDetachShader}(GLuint program,...
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
int glCreateProgram()
Entry point to C language function: GLuint {@native glCreateProgram}() Part of GL_ES_VERSION_2_0,...
void glShaderSource(int shader, int count, String[] string, IntBuffer length)
Entry point to C language function: void {@native glShaderSource}(GLuint shader, GLsizei count,...
void glAttachShader(int program, int shader)
Entry point to C language function: void {@native glAttachShader}(GLuint program,...
void glDeleteProgram(int program)
Entry point to C language function: void {@native glDeleteProgram}(GLuint program) Part of GL_ES_V...
int glCreateShader(int type)
Entry point to C language function: GLuint {@native glCreateShader}(GLenum type) Part of GL_ES_VER...
void glLinkProgram(int program)
Entry point to C language function: void {@native glLinkProgram}(GLuint program) Part of GL_ES_VER...
static final int GL_SEPARATE_ATTRIBS
GL_ES_VERSION_3_0, GL_VERSION_3_0, GL_EXT_transform_feedback, GL_NV_transform_feedback Alias for: GL_...
Definition: GL2ES3.java:850
void glTransformFeedbackVaryings(int program, int count, String[] varyings, int bufferMode)
Entry point to C language function: void {@native glTransformFeedbackVaryings}(GLuint program,...
GL getGL()
Casts this object to the GL interface.
GL3 getGL3()
Casts this object to the GL3 interface.
static final int GL_NO_ERROR
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NO_ERROR" with expres...
Definition: GL.java:481
int glGetError()
Entry point to C language function: GLenum {@native glGetError}() Part of GL_ES_VERSION_2_0,...