28package com.jogamp.opengl.test.junit.jogl.glsl;
30import com.jogamp.common.nio.Buffers;
31import com.jogamp.newt.Window;
32import com.jogamp.newt.event.KeyAdapter;
33import com.jogamp.newt.event.KeyEvent;
34import com.jogamp.newt.opengl.GLWindow;
35import com.jogamp.opengl.util.GLArrayDataServer;
36import com.jogamp.opengl.util.PMVMatrix;
37import com.jogamp.opengl.util.glsl.ShaderCode;
38import com.jogamp.opengl.util.glsl.ShaderProgram;
39import com.jogamp.opengl.util.glsl.ShaderState;
40import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
41import com.jogamp.opengl.test.junit.util.MiscUtils;
42import com.jogamp.opengl.test.junit.util.UITestCase;
44import java.io.IOException;
45import java.lang.reflect.InvocationTargetException;
46import java.nio.FloatBuffer;
48import com.jogamp.nativewindow.ScalableSurface;
49import com.jogamp.opengl.GL;
50import com.jogamp.opengl.GL2ES2;
51import com.jogamp.opengl.GLAutoDrawable;
52import com.jogamp.opengl.GLCapabilities;
53import com.jogamp.opengl.GLEventListener;
54import com.jogamp.opengl.GLProfile;
55import com.jogamp.opengl.GLUniformData;
56import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
58import org.junit.Assert;
60import org.junit.FixMethodOrder;
61import org.junit.runners.MethodSorters;
63@FixMethodOrder(MethodSorters.NAME_ASCENDING)
65 static long durationPerTest = 500;
67 static boolean manualTest =
false;
69 private void setTitle(
final Window win) {
76 private void runTestGL()
throws InterruptedException {
78 Assert.assertNotNull(glWindow);
97 "shader/bin",
"default",
true);
99 "shader/bin",
"ruler",
true);
104 sp0.
add(gl, vp0, System.err);
105 sp0.
add(gl, fp0, System.err);
106 Assert.assertTrue(0 != sp0.
program());
107 Assert.assertTrue(!sp0.
inUse());
108 Assert.assertTrue(!sp0.
linked());
115 st.
uniform(gl, pmvMatrixUniform);
119 final FloatBuffer rulerColorV = (FloatBuffer) rulerColor.
getBuffer();
120 rulerColorV.put(0, 0.5f);
121 rulerColorV.put(1, 0.5f);
122 rulerColorV.put(2, 0.5f);
129 vertices0.
putf(0); vertices0.
putf(1); vertices0.
putf(0);
130 vertices0.
putf(1); vertices0.
putf(1); vertices0.
putf(0);
131 vertices0.
putf(0); vertices0.
putf(0); vertices0.
putf(0);
132 vertices0.
putf(1); vertices0.
putf(0); vertices0.
putf(0);
133 vertices0.
seal(gl,
true);
156 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {
160 pmvMatrix.
glOrthof(0f, 1f, 0f, 1f, -10f, 10f);
166 st.
uniform(gl, pmvMatrixUniform);
169 final FloatBuffer rulerPixFreqV = (FloatBuffer) rulerPixFreq.
getBuffer();
170 rulerPixFreqV.put(0, ppmmStore[0] * 10.0f);
171 rulerPixFreqV.put(1, ppmmStore[1] * 10.0f);
173 System.err.println(
"Screen pixel/cm "+rulerPixFreqV.get(0)+
", "+rulerPixFreqV.get(1));
181 public void keyPressed(
final KeyEvent e) {
187 final float[] reqSurfacePixelScale;
193 System.err.println(
"[set PixelScale pre]: had "+hadSurfacePixelScale[0]+
"x"+hadSurfacePixelScale[1]+
" -> req "+reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]);
199 System.err.println(
"[set PixelScale post]: "+hadSurfacePixelScale[0]+
"x"+hadSurfacePixelScale[1]+
" (had) -> "+
200 reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" (req) -> "+
201 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" (val) -> "+
202 hasSurfacePixelScale[0]+
"x"+hasSurfacePixelScale[1]+
" (has), "+
203 nativeSurfacePixelScale[0]+
"x"+nativeSurfacePixelScale[1]+
" (native)");
212 System.err.println(
"HiDPI PixelScale: "+reqSurfacePixelScale[0]+
"x"+reqSurfacePixelScale[1]+
" (req) -> "+
213 valReqSurfacePixelScale[0]+
"x"+valReqSurfacePixelScale[1]+
" (val) -> "+
214 hasSurfacePixelScale1[0]+
"x"+hasSurfacePixelScale1[1]+
" (has)");
220 Thread.sleep(durationPerTest);
232 public void test99_PS1() throws InterruptedException, InvocationTargetException {
233 if(manualTest)
return;
239 public static void main(
final String args[])
throws IOException {
240 System.err.println(
"main - start");
241 for(
int i=0; i<args.length; i++) {
242 if(args[i].equals(
"-time")) {
243 durationPerTest =
MiscUtils.
atoi(args[++i], (
int)durationPerTest);
244 }
else if(args[i].equals(
"-pixelScale")) {
246 final float pS =
MiscUtils.
atof(args[i], reqSurfacePixelScale[0]);
247 reqSurfacePixelScale[0] = pS;
248 reqSurfacePixelScale[1] = pS;
249 }
else if(args[i].equals(
"-manual")) {
254 org.junit.runner.JUnitCore.
main(tstname);
255 System.err.println(
"main - end");
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final float[] getMaximumSurfaceScale(final float[] result)
Returns the maximum pixel scale of the associated NativeSurface.
final float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter of this window's NativeSurface according to the main monitor's curr...
final float[] getRequestedSurfaceScale(final float[] result)
Returns the requested pixel scale of the associated NativeSurface.
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final float[] getCurrentSurfaceScale(final float[] result)
Returns the current pixel scale of the associated NativeSurface.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final boolean setSurfaceScale(final float[] pixelScale)
Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_uni...
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
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 void main(final String args[])
static float atof(final String str, final float def)
static int atoi(final String str, final int def)
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
void enableBuffer(final GL gl, final boolean enable)
Enables the buffer if enable is true, and transfers the data if required.
static GLArrayDataServer createGLSL(final String name, final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO, using a custom GLSL array attribute name and starting with a new created Buffer object ...
PMVMatrix implements a subset of the fixed function pipeline GLMatrixFunc using PMVMatrix4f.
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
final void glOrthof(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Multiply the current matrix with the orthogonal 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 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 ...
void ownAttribute(final GLArrayData attribute, final boolean own)
Binds or unbinds the GLArrayData lifecycle to this ShaderState.
synchronized boolean attachShaderProgram(final GL2ES2 gl, final ShaderProgram prog, final boolean enable)
Attach or switch a shader program.
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.
int getSurfaceWidth()
Returns the width of the client area excluding insets (window decorations) in pixel units.
int getSurfaceHeight()
Returns the height of the client area excluding insets (window decorations) in pixel units.
Rectangle getBounds()
Returns a newly created Rectangle containing window origin, getX() & getY(), and size,...
Adding mutable surface pixel scale property to implementing class, usually to a NativeSurface impleme...
static final float IDENTITY_PIXELSCALE
Setting surface-pixel-scale of {@value}, results in same pixel- and window-units.
static final float AUTOMAX_PIXELSCALE
Setting surface-pixel-scale of {@value}, results in maximum platform dependent pixel-scale,...
Specifying NEWT's Window functionality:
void setTitle(String title)
float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter of this window's NativeSurface according to the main monitor's curr...
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...
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...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void glDrawArrays(int mode, int first, int count)
Entry point to C language function: void {@native glDrawArrays}(GLenum mode, GLint first,...
static final int GL_STATIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_STATI...
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expressio...
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,...
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
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 glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
static final int GL_TRIANGLE_STRIP
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLE_STRIP" with ...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...
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.