29package com.jogamp.opengl.test.junit.jogl.demos.es2;
31import static com.jogamp.opengl.GL.*;
33import java.nio.FloatBuffer;
35import com.jogamp.opengl.GL;
36import com.jogamp.opengl.GL2ES2;
37import com.jogamp.opengl.GLAutoDrawable;
38import com.jogamp.opengl.GLCapabilities;
39import com.jogamp.opengl.GLCapabilitiesImmutable;
40import com.jogamp.opengl.GLEventListener;
41import com.jogamp.opengl.GLProfile;
42import com.jogamp.opengl.GLUniformData;
43import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
45import com.jogamp.common.nio.Buffers;
46import com.jogamp.common.os.Clock;
47import com.jogamp.newt.event.KeyAdapter;
48import com.jogamp.newt.event.KeyEvent;
49import com.jogamp.newt.opengl.GLWindow;
50import com.jogamp.opengl.util.GLArrayDataServer;
51import com.jogamp.opengl.util.PMVMatrix;
52import com.jogamp.opengl.util.glsl.ShaderCode;
53import com.jogamp.opengl.util.glsl.ShaderProgram;
54import com.jogamp.opengl.util.glsl.ShaderState;
127 private final String mCommandLineParameter_BaseRoutineClassName;
128 private final boolean mCommandLineParameter_MultiSampling;
129 private final int mCommandLineParameter_NumberOfSampleBuffers;
130 private final boolean mCommandLineParameter_AnisotropicFiltering;
131 private final float mCommandLineParameter_AnisotropyLevel;
132 private final boolean mCommandLineParameter_FrameCapture;
133 private final boolean mCommandLineParameter_FrameSkip;
134 private boolean mUsesFullScreenMode;
135 private int mFrameCounter;
136 private final int mCommandLineParameter_FrameRate;
137 private long mFrameSkipAverageFramerateTimeStart;
138 private long mFrameSkipAverageFramerateTimeEnd;
139 private boolean mFrameSkipManual;
142 boolean mMusicSyncStartTimeInitialized =
false;
163 public void keyPressed(
final KeyEvent e) {
166 }
else if(KeyEvent.VK_LEFT == e.
getKeyCode()) {
171 TimeShiftKeys timeShiftKeys;
174 final String inBaseRoutineClassName,
175 final boolean inMultiSampling,
176 final int inNumberOfSampleBuffers,
177 final boolean inAnisotropicFiltering,
178 final float inAnisotropyLevel,
179 final boolean inFrameCapture,
180 final boolean inFrameSkip,
final int desiredFrameRate,
final int startFrame
183 mCommandLineParameter_BaseRoutineClassName = inBaseRoutineClassName;
184 mCommandLineParameter_MultiSampling = inMultiSampling;
185 mCommandLineParameter_NumberOfSampleBuffers = (inNumberOfSampleBuffers==-1) ? 2 : inNumberOfSampleBuffers;
186 mCommandLineParameter_AnisotropicFiltering = inAnisotropicFiltering;
187 mCommandLineParameter_AnisotropyLevel = (inAnisotropyLevel==-1.0f) ? 2.0f : inAnisotropyLevel;
188 mCommandLineParameter_FrameCapture = inFrameCapture;
189 mCommandLineParameter_FrameSkip = inFrameSkip;
190 mCommandLineParameter_FrameRate = desiredFrameRate;
204 mFrameSkipAverageFramerateTimeStart = 0;
207 timeShiftKeys =
new TimeShiftKeys();
211 this(
null,
false, -1,
false, -1.0f,
false,
true, 30, 0);
219 final long dft = 1000000000/mCommandLineParameter_FrameRate;
220 mFrameSkipAverageFramerateTimeStart -= frames * dft ;
221 mFrameSkipManual =
true;
239 "shader/bin",
"default",
true);
241 "shader/bin",
"elektronenmultiplizierer_development",
true);
247 sp0.
add(gl, vp0, System.err);
248 sp0.
add(gl, fp0, System.err);
254 mScreenDimensionUniform =
new GLUniformData(
"resolution", 2, Buffers.newDirectFloatBuffer(2));
255 final FloatBuffer mScreenDimensionV = (FloatBuffer) mScreenDimensionUniform.
getBuffer();
256 mScreenDimensionV.put(0, XRESf);
257 mScreenDimensionV.put(1, YRESf);
259 st.
uniform(gl, mScreenDimensionUniform);
264 st.
uniform(gl, pmvMatrixUniform);
267 vertices0.
putf(0); vertices0.
putf(YRESf);
268 vertices0.
putf(XRESf); vertices0.
putf(YRESf);
269 vertices0.
putf(0); vertices0.
putf(0);
270 vertices0.
putf(XRESf); vertices0.
putf(0);
271 vertices0.
seal(gl,
true);
286 final int[] result =
new int[1];
291 gl.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
292 gl.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
293 gl.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 384, 384, 0, GL_RGBA, GL_UNSIGNED_BYTE,
null);
314 mFrameSkipAverageFramerateTimeStart += Clock.currentNanos();
324 mFrameSkipAverageFramerateTimeEnd = Clock.currentNanos();
326 final double tSingleFrameTime = 1000000000.0f/tDesiredFrameRate;
327 final double tElapsedTime = mFrameSkipAverageFramerateTimeEnd - mFrameSkipAverageFramerateTimeStart;
328 final double mFrameCounterTargetValue = tElapsedTime/tSingleFrameTime;
329 final double mFrameCounterDifference = mFrameCounterTargetValue-mFrameCounter;
330 if (mFrameSkipManual || mFrameCounterDifference>2) {
331 mFrameCounter+=mFrameCounterDifference;
333 }
else if (mFrameCounterDifference<-2) {
337 mFrameSkipManual =
false;
357 int MMTime_u_ms = (int)(((mFrameCounter)*44100.0f)/60.0f);
370 MMTime_u_ms = (int)(((mFrameCounter)*44100.0f)/60.0f);
381 pmvMatrix.
glOrthof(0f, XRES, YRES, 0f, -1f, 1f);
384 st.
uniform(gl, pmvMatrixUniform);
389 float tBrightnessSync = 40.0f-((MMTime_u_ms-
mSyncTime)/1000.0f);
390 if (tBrightnessSync<1) {
407 final float tEffectTimeMax = 9.3f;
482 vertices0.
seal(
false);
484 vertices0.
putf(0); vertices0.
putf(height);
485 vertices0.
putf(width); vertices0.
putf(height);
486 vertices0.
putf(0); vertices0.
putf(0);
487 vertices0.
putf(width); vertices0.
putf(0);
488 vertices0.
seal(gl,
true);
492 final FloatBuffer mScreenDimensionV = (FloatBuffer) mScreenDimensionUniform.
getBuffer();
493 mScreenDimensionV.put(0, width);
494 mScreenDimensionV.put(1, height);
495 st.
uniform(gl, mScreenDimensionUniform);
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
static final short VK_RIGHT
Constant for the cursor- or numerical-pad right arrow key.
final short getKeyCode()
Returns the virtual key code using a fixed mapping to the US keyboard layout.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final void removeKeyListener(final KeyListener l)
Specifies a set of OpenGL capabilities.
void setAccumRedBits(final int accumRedBits)
Sets the number of bits requested for the accumulation buffer's red component.
void setAccumGreenBits(final int accumGreenBits)
Sets the number of bits requested for the accumulation buffer's green component.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setAccumBlueBits(final int accumBlueBits)
Sets the number of bits requested for the accumulation buffer's blue component.
void setAccumAlphaBits(final int accumAlphaBits)
Sets number of bits requested for accumulation buffer's alpha component.
void setSampleBuffers(final boolean enable)
Defaults to false.
Specifies the the OpenGL profile.
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
String getBaseRoutineClassName()
ElektronenMultiplizierer(final String inBaseRoutineClassName, final boolean inMultiSampling, final int inNumberOfSampleBuffers, final boolean inAnisotropicFiltering, final float inAnisotropyLevel, final boolean inFrameCapture, final boolean inFrameSkip, final int desiredFrameRate, final int startFrame)
ElektronenMultiplizierer()
float getAnisotropyLevel()
int mFrameBufferTextureID
boolean usesFullScreenMode()
boolean preferMultiSampling()
int getDesiredFramerate()
GLCapabilitiesImmutable getGLCapabilities()
void handleSyncEvent(final int inMMTime_u_ms)
void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
int getNumberOfSamplingBuffers()
boolean preferAnisotropicFiltering()
boolean wantsFrameCapture()
void skipFrames(final int frames)
skip frames by turning back start time
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void seal(final GL gl, final boolean seal)
Convenience method calling seal(boolean) and enableBuffer(GL, boolean).
void rewind()
Rewinds this buffer.
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,...
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 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...
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.
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.
boolean isGLcore()
Indicates whether this GL object uses a GL core profile.
Specifies an immutable set of OpenGL capabilities.
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.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void glFramebufferTexture2D(int target, int attachment, int textarget, int texture, int level)
Entry point to C language function: void {@native glFramebufferTexture2D}(GLenum target,...
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...
void glDeleteTextures(int n, IntBuffer textures)
Entry point to C language function: void {@native glDeleteTextures}(GLsizei n, const GLuint * textur...
void glBindTexture(int target, int texture)
Entry point to C language function: void {@native glBindTexture}(GLenum target, GLuint texture) Pa...
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...
void glDisable(int cap)
Entry point to C language function: void {@native glDisable}(GLenum cap) Part of GL_ES_VERSION_2_0...
void glGenTextures(int n, IntBuffer textures)
Entry point to C language function: void {@native glGenTextures}(GLsizei n, GLuint * textures) Par...
void glGenFramebuffers(int n, IntBuffer framebuffers)
Entry point to C language function: void {@native glGenFramebuffers}(GLsizei n, GLuint * framebuffer...
void glDeleteFramebuffers(int n, IntBuffer framebuffers)
Entry point to C language function: void {@native glDeleteFramebuffers}(GLsizei n,...
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,...
void glActiveTexture(int texture)
Entry point to C language function: void {@native glActiveTexture}(GLenum texture) Part of GL_ES_V...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glTexParameteri(int target, int pname, int param)
Entry point to C language function: void {@native glTexParameteri}(GLenum target,...
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 ...
void glBindFramebuffer(int target, int framebuffer)
Entry point to C language function: void {@native glBindFramebuffer}(GLenum target,...
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,...
void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int type, Buffer pixels)
Entry point to C language function: void {@native glTexImage2D}(GLenum target, GLint level,...
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.