28package com.jogamp.opengl.test.junit.jogl.glsl;
30import com.jogamp.opengl.util.GLArrayDataServer;
31import com.jogamp.opengl.util.PMVMatrix;
32import com.jogamp.opengl.util.glsl.ShaderCode;
33import com.jogamp.opengl.util.glsl.ShaderProgram;
34import com.jogamp.opengl.util.glsl.ShaderState;
35import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
36import com.jogamp.opengl.test.junit.util.MiscUtils;
37import com.jogamp.opengl.test.junit.util.NEWTGLContext;
38import com.jogamp.opengl.test.junit.util.UITestCase;
40import java.io.IOException;
42import com.jogamp.math.FloatUtil;
43import com.jogamp.opengl.GL;
44import com.jogamp.opengl.GL2ES2;
45import com.jogamp.opengl.GLCapabilities;
46import com.jogamp.opengl.GLDrawable;
47import com.jogamp.opengl.GLProfile;
48import com.jogamp.opengl.GLUniformData;
49import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
51import org.junit.Assert;
53import org.junit.FixMethodOrder;
54import org.junit.runners.MethodSorters;
60@FixMethodOrder(MethodSorters.NAME_ASCENDING)
62 static long durationPerTest = 10;
63 static boolean firstUIActionOnProcess =
false;
65 static final int vertices0_loc = 0;
66 static final int colors0_loc = 1;
73 final GLDrawable drawable = winctx.context.getGLDrawable();
75 System.err.println(winctx.context);
81 "shader",
"shader/bin",
"RedSquareShader",
true);
83 "shader",
"shader/bin",
"RedSquareShader",
true);
88 Assert.assertTrue(0 == sp.
program());
90 sp.
add(gl, rsVp, System.err);
91 sp.
add(gl, rsFp, System.err);
93 Assert.assertTrue(0 != sp.
program());
94 Assert.assertTrue(!sp.
inUse());
95 Assert.assertTrue(!sp.
linked());
98 Assert.assertTrue( sp.
link(gl, System.err) );
103 System.err.println(
"vertices0: " + vertices0);
105 Assert.assertEquals(vertices0_loc, vertices0.
getLocation());
109 System.err.println(
"colors0: " + colors0);
111 Assert.assertEquals(colors0_loc, colors0.
getLocation());
113 Assert.assertTrue(sp.
link(gl, System.err));
114 Assert.assertTrue(sp.
linked());
117 Assert.assertEquals(vertices0_loc, vertices0.
getLocation());
120 Assert.assertEquals(colors0_loc, colors0.
getLocation());
124 Assert.assertTrue(sp.
inUse());
138 System.err.println(
"vertices1: " + vertices1);
144 System.err.println(
"colors1: " + colors1);
189 final GLDrawable drawable = winctx.context.getGLDrawable();
191 System.err.println(winctx.context);
199 "shader/bin",
"RedSquareShader",
true);
201 "shader/bin",
"RedSquareShader",
true);
206 Assert.assertTrue(0 == sp.
program());
208 sp.
add(gl, rsVp, System.err);
209 sp.
add(gl, rsFp, System.err);
211 Assert.assertTrue(0 != sp.
program());
212 Assert.assertTrue(!sp.
inUse());
213 Assert.assertTrue(!sp.
linked());
217 Assert.assertTrue(!sp.
inUse());
218 Assert.assertTrue(!sp.
linked());
222 System.err.println(
"vertices0: " + vertices0);
224 Assert.assertEquals(vertices0_loc, vertices0.
getLocation());
228 System.err.println(
"colors0: " + colors0);
230 Assert.assertEquals(colors0_loc, colors0.
getLocation());
232 Assert.assertTrue(sp.
link(gl, System.err));
233 Assert.assertTrue(sp.
linked());
236 Assert.assertEquals(vertices0_loc, vertices0.
getLocation());
239 Assert.assertEquals(colors0_loc, colors0.
getLocation());
243 Assert.assertTrue(sp.
inUse());
252 st.
uniform(gl, pmvMatrixUniform);
254 Assert.assertEquals(pmvMatrixUniform, st.
getUniform(
"mgl_PMVMatrix"));
258 System.err.println(
"vertices1: " + vertices1);
264 System.err.println(
"colors1: " + colors1);
280 st.
uniform(gl, pmvMatrixUniform);
299 @Test(timeout=240000)
300 public
void test02ShaderState_PerformanceSingleKeepEnabled() throws InterruptedException {
301 testShaderState_PerformanceSingleImpl(
false);
303 @Test(timeout=240000)
304 public
void test03ShaderState_PerformanceSingleToggleEnable() throws InterruptedException {
305 testShaderState_PerformanceSingleImpl(
true);
308 private void testShaderState_PerformanceSingleImpl(
final boolean toggleEnable)
throws InterruptedException {
312 final GLDrawable drawable = winctx.context.getGLDrawable();
314 System.err.println(winctx.context);
323 "shader/bin",
"RedSquareShader",
true);
325 "shader/bin",
"RedSquareShader",
true);
334 Assert.assertTrue(sp.
link(gl, System.err));
342 st.
uniform(gl, pmvMatrixUniform);
346 vertices0.
enableBuffer(gl, toggleEnable ?
false :
true);
363 st.
uniform(gl, pmvMatrixUniform);
377 final long t0 = System.currentTimeMillis();
380 for(frames=0; frames<GLSLMiscHelper.frames_perftest; frames++) {
381 GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, toggleEnable, vertices0, colors0, toggleEnable);
383 final long t1 = System.currentTimeMillis();
384 final long dt = t1 - t0;
385 final double fps = ( frames * 1000.0 ) / dt;
386 final String fpsS = String.valueOf(fps);
387 final int fpsSp = fpsS.indexOf(
'.');
388 System.err.println(
"testShaderState00PerformanceSingle toggleEnable "+toggleEnable+
": "+dt/1000.0 +
"s: "+ frames +
"f, " + fpsS.substring(0, fpsSp+2) +
" fps, "+dt/frames+
" ms/f");
393 NEWTGLContext.destroyWindow(winctx);
396 @Test(timeout=240000)
397 public
void test04ShaderState_PerformanceDouble() throws InterruptedException {
401 final GLDrawable drawable = winctx.context.getGLDrawable();
403 System.err.println(winctx.context);
412 "shader/bin",
"RedSquareShader",
true);
414 "shader/bin",
"RedSquareShader",
true);
423 Assert.assertTrue(sp.
link(gl, System.err));
431 st.
uniform(gl, pmvMatrixUniform);
460 st.
uniform(gl, pmvMatrixUniform);
476 final long t0 = System.currentTimeMillis();
483 final long t1 = System.currentTimeMillis();
484 final long dt = t1 - t0;
485 final double fps = ( frames * 1000.0 ) / dt;
486 final String fpsS = String.valueOf(fps);
487 final int fpsSp = fpsS.indexOf(
'.');
488 System.err.println(
"testShaderState01PerformanceDouble: "+dt/1000.0 +
"s: "+ frames +
"f, " + fpsS.substring(0, fpsSp+2) +
" fps, "+dt/frames+
" ms/f");
496 public static void main(
final String args[])
throws IOException {
497 System.err.println(
"main - start");
498 boolean wait =
false;
499 for(
int i=0; i<args.length; i++) {
500 if(args[i].equals(
"-time")) {
501 durationPerTest =
MiscUtils.
atoi(args[++i], (
int)durationPerTest);
502 }
else if(args[i].equals(
"-wait")) {
504 }
else if(args[i].equals(
"-firstUIAction")) {
505 firstUIActionOnProcess =
true;
509 while(-1 == System.in.read()) ;
513 }
catch (
final Exception e) {
518 org.junit.runner.JUnitCore.
main(tstname);
520 System.err.println(
"main - end");
Basic Float math utility functions.
static final float QUARTER_PI
The value PI/4, i.e.
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
static final float[] vertices0
static final int frames_perftest
static void validateGLArrayDataServerState(final GL2ES2 gl, final ShaderState st, final GLArrayDataServer data)
static final float[] colors0
static GLArrayDataServer createColors(final GL2ES2 gl, final ShaderState st, final int shaderProgram, final int location, final float[] colors)
static final float[] vertices1
static GLArrayDataServer createVertices(final GL2ES2 gl, final ShaderState st, final int shaderProgram, final int location, final float[] vertices)
static final int frames_warmup
static void displayVCArrays(final GLDrawable drawable, final GL2ES2 gl, final ShaderState st, final boolean preEnable, final GLArrayDataServer vertices, final GLArrayDataServer colors, final boolean postDisable, final int num, final long postDelay)
static final float[] colors1
static void displayVCArraysNoChecks(final GLDrawable drawable, final GL2ES2 gl, final boolean preEnable, final GLArrayDataServer vertices, final GLArrayDataServer colors, final boolean postDisable)
Testing different vertex attribute (VA) data sets on one shader and shader state in general.
void test04ShaderState_PerformanceDouble()
void test01ShaderState_Validation()
static void main(final String args[])
void test00NoShaderState_Validation()
static int atoi(final String str, final int def)
static WindowContext createWindow(final GLCapabilities caps, final int width, final int height, final boolean debugGL)
static void destroyWindow(final WindowContext winctx)
void enableBuffer(final GL gl, final boolean enable)
Enables the buffer if enable is true, and transfers the data if required.
void destroy(final GL gl)
final int getLocation()
Returns the shader attribute location for this name, -1 if not yet determined.
PMVMatrix implements a subset of the fixed function pipeline GLMatrixFunc using PMVMatrix4f.
final void glTranslatef(final float x, final float y, final float z)
Translate the current matrix.
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
final void gluPerspective(final float fovy_rad, final float aspect, final float zNear, final float zFar)
Multiply the current matrix with the perspective/frustum matrix.
final void glLoadIdentity()
Load the current matrix with the identity matrix.
Convenient shader code class to use and instantiate vertex or fragment programs.
final int defaultShaderCustomization(final GL2ES2 gl, final boolean preludeVersion, final boolean addDefaultPrecision)
Default customization of this shader source code.
static ShaderCode create(final GL2ES2 gl, final int type, final int count, final Class<?> context, final String[] sourceFiles, final boolean mutableStringBuilder)
Creates a complete ShaderCode object while reading all shader source of sourceFiles,...
int program()
Returns the shader program name, which is non zero if valid.
synchronized final boolean init(final GL2ES2 gl)
Creates the empty GL program object using GL2ES2#glCreateProgram(), if not already created.
synchronized void destroy(final GL2ES2 gl)
Detaches all shader codes and deletes the program.
synchronized void useProgram(final GL2ES2 gl, boolean on)
synchronized boolean link(final GL2ES2 gl, final PrintStream verboseOut)
Links the shader code to the program.
synchronized void add(final ShaderCode shaderCode)
Adds a new shader to this program.
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform ...
synchronized void useProgram(final GL2ES2 gl, final boolean on)
Turns the shader program on or off.
synchronized boolean attachShaderProgram(final GL2ES2 gl, final ShaderProgram prog, final boolean enable)
Attach or switch a shader program.
GLUniformData getUniform(final String name)
Get the uniform data, previously set.
synchronized void destroy(final GL2ES2 gl)
Calls release(gl, true, true, true).
boolean uniform(final GL2ES2 gl, final GLUniformData data)
Set the uniform data, if it's location is valid, i.e.
void ownUniform(final GLUniformData uniform)
Bind the GLUniform lifecycle to this ShaderState.
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 glUniform(GLUniformData data)
static final int GL_FRAGMENT_SHADER
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ATI_fragment_shader, GL_ARB_fragment_shader Alias for: GL_FRAGM...
GL getGL()
Casts this object to the GL interface.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
An abstraction for an OpenGL rendering target.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
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,...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
void glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
static final int GL_DEPTH_TEST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_TEST" with expr...
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
static final int GL_MODELVIEW
Matrix mode modelview.