1package com.jogamp.opengl.test.junit.jogl.glsl;
3import com.jogamp.opengl.test.junit.util.NEWTGLContext;
4import com.jogamp.opengl.test.junit.util.UITestCase;
6import java.io.ByteArrayOutputStream;
7import java.io.PrintStream;
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;
17import org.junit.Assert;
19import org.junit.FixMethodOrder;
20import org.junit.runners.MethodSorters;
22import com.jogamp.opengl.util.glsl.ShaderUtil;
24import java.io.IOException;
30@FixMethodOrder(MethodSorters.NAME_ASCENDING)
33 private static final boolean debugGL =
true;
35 private static final String VERTEX_SHADER_TEXT =
38 +
"out vec4 Position; \n"
41 +
" Position = vec4(1.0, 1.0, 1.0, 1.0); \n"
44 static class MyShader {
48 MyShader(
final int shaderProgram,
final int vertShader) {
49 this.shaderProgram = shaderProgram;
50 this.vertShader = vertShader;
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);
62 final String[] lines =
new String[]{text};
63 final int[] lengths =
new int[]{lines[0].length()};
68 System.out.println(
"getShader:postCompile: "+baos.toString());
69 Assert.assertTrue(
false);
71 pbaos.flush(); baos.reset();
76 return new MyShader(shaderProgram, vertShader);
79 private void releaseShader(
final GL3 gl,
final MyShader myShader) {
90 private NEWTGLContext.WindowContext prepareTest()
throws GLException, InterruptedException {
93 if(!winctx.context.getGL().isGL3()) {
94 System.err.println(
"GL3 not available");
98 Assert.assertEquals(
GL.
GL_NO_ERROR, winctx.context.getGL().glGetError());
109 public
void testGlTransformFeedbackVaryings_WhenVarNameOK() throws
GLException, InterruptedException {
110 final NEWTGLContext.WindowContext winctx = prepareTest();
114 final ByteArrayOutputStream baos =
new ByteArrayOutputStream();
115 final PrintStream pbaos =
new PrintStream(baos);
123 final String[] vars =
new String[]{
"Position"};
133 boolean error =
false;
136 System.out.println(
"Error (unexpected link error) - testGlTransformFeedbackVaryings_WhenVarNameOK:postLink: "+baos.toString());
139 pbaos.flush(); baos.reset();
142 releaseShader(gl, myShader);
144 Assert.assertFalse(error);
148 public
void testGlTransformFeedbackVaryings_WhenVarNameWrong() throws
GLException, InterruptedException {
149 final NEWTGLContext.WindowContext winctx = prepareTest();
153 final ByteArrayOutputStream baos =
new ByteArrayOutputStream();
154 final PrintStream pbaos =
new PrintStream(baos);
162 final String[] vars =
new String[]{
"PPPosition"};
171 boolean error =
false;
174 System.out.println(
"GOOD (expected link error) - testGlTransformFeedbackVaryings_WhenVarNameWrong:postLink: "+baos.toString());
178 System.out.println(
"Error (unexpected link success) - testGlTransformFeedbackVaryings_WhenVarNameWrong link worked, but it should not");
181 pbaos.flush(); baos.reset();
184 releaseShader(gl, myShader);
187 Assert.assertFalse(error);
190 public static void main(
final String args[])
throws IOException {
192 org.junit.runner.JUnitCore.
main(tstname);
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.
static final String GL3
The desktop OpenGL core profile 3.x, with x >= 1.
static GLProfile getMaxProgrammable(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the programmable shader pipeline.
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)
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...
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',...
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_...
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...
int glGetError()
Entry point to C language function: GLenum {@native glGetError}() Part of GL_ES_VERSION_2_0,...