28package com.jogamp.opengl.test.junit.jogl.demos.es2;
30import com.jogamp.opengl.util.GLArrayDataServer;
31import com.jogamp.opengl.util.glsl.ShaderCode;
32import com.jogamp.opengl.util.glsl.ShaderProgram;
33import com.jogamp.opengl.util.glsl.ShaderState;
34import java.nio.FloatBuffer;
36import com.jogamp.opengl.GL;
37import com.jogamp.opengl.GL2ES2;
38import com.jogamp.opengl.GLAutoDrawable;
39import com.jogamp.opengl.GLEventListener;
40import com.jogamp.opengl.GLUniformData;
46 private int swapInterval = 0;
47 private boolean verbose =
true;
50 private long millisOffset;
51 private int frameCount;
52 private float frameRate;
57 private float[] resolution;
62 private int fcount = 0, lastm = 0;
63 private final int fint = 1;
66 this.swapInterval = swapInterval;
70 this.swapInterval = 1;
77 System.err.println(Thread.currentThread()+
" LandscapeES2.init ...");
81 System.err.println(
"LandscapeES2 init on "+Thread.currentThread());
83 System.err.println(
"INIT GL IS: " + gl.getClass().getName());
99 shaderProg.
add(gl, vertShader, System.err);
100 shaderProg.
add(gl, fragShader, System.err);
106 resolutionUni =
new GLUniformData(
"iResolution", 3, FloatBuffer.wrap(resolution));
108 shaderState.
uniform(gl, resolutionUni);
114 vertices.
putf(-1.0f); vertices.
putf(-1.0f);
115 vertices.
putf(+1.0f); vertices.
putf(-1.0f);
116 vertices.
putf(-1.0f); vertices.
putf(+1.0f);
117 vertices.
putf(+1.0f); vertices.
putf(+1.0f);
118 vertices.
seal(gl,
true);
122 millisOffset = System.currentTimeMillis();
124 System.err.println(Thread.currentThread()+
" LandscapeES2.init FIN");
129 System.err.println(Thread.currentThread()+
" LandscapeES2.reshape "+x+
"/"+y+
" "+width+
"x"+height+
", swapInterval "+swapInterval+
", drawable 0x"+Long.toHexString(drawable.
getHandle()));
139 shaderState.
uniform(gl, resolutionUni);
146 System.err.println(Thread.currentThread()+
" LandscapeES2.dispose ... ");
152 System.err.println(Thread.currentThread()+
" LandscapeES2.dispose FIN");
164 timeUni.
setData((System.currentTimeMillis() - millisOffset) / 1000.0f);
165 shaderState.
uniform(gl, timeUni);
175 final int m = (int) (System.currentTimeMillis() - millisOffset);
176 if (m - lastm > 1000 * fint) {
177 frameRate = (float)(fcount) / fint;
182 System.out.println(
"FrameCount: " + frameCount +
" - " +
"FrameRate: " + frameRate);
186 boolean confinedFixedCenter =
false;
189 confinedFixedCenter = v;
final GLRendererQuirks getRendererQuirks()
Returns the instance of GLRendererQuirks, allowing one to determine workarounds.
final String getGLVersion()
Returns a valid OpenGL version string, ie
final StringBuilder toString(StringBuilder sb)
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
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.
LandscapeES2(final int swapInterval)
void setConfinedFixedCenter(final boolean v)
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void setVerbose(final boolean v)
static final int TARGET_FPS
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 ...
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.
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_SHADING_LANGUAGE_VERSION
GL_ES_VERSION_2_0, GL_VERSION_2_0, GL_ARB_shading_language_100 Alias for: GL_SHADING_LANGUAGE_VERSION...
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.
boolean hasGLSL()
Indicates whether this GL object supports GLSL.
boolean hasBasicFBOSupport()
Returns true if basic FBO support is available, otherwise false.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
void setSwapInterval(int interval)
Set the swap interval of the current context and attached onscreen GLDrawable.
GLContext getContext()
Returns the GLContext associated which this GL object.
boolean isFunctionAvailable(String glFunctionName)
Returns true if the specified OpenGL core- or extension-function can be used successfully through thi...
boolean hasFullFBOSupport()
Returns true if full FBO support is available, otherwise false.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
long getHandle()
Returns the GL drawable handle, guaranteed to be valid after realization and while it's surface is be...
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 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_VERSION
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VERSION" with express...
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...
String glGetString(int name)
Entry point to C language function: const GLubyte * {@native glGetString}(GLenum name) Part of GL_...
static final int GL_RENDERER
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RENDERER" with expres...
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_VENDOR
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VENDOR" with expressi...