28package com.jogamp.opengl.test.junit.jogl.demos.es2;
30import com.jogamp.opengl.JoglVersion;
31import com.jogamp.opengl.util.GLArrayDataServer;
32import com.jogamp.opengl.util.PMVMatrix;
33import com.jogamp.opengl.util.TileRendererBase;
34import com.jogamp.opengl.util.glsl.ShaderCode;
35import com.jogamp.opengl.util.glsl.ShaderProgram;
36import com.jogamp.opengl.util.glsl.ShaderState;
38import com.jogamp.opengl.GL;
39import com.jogamp.opengl.GL2ES2;
40import com.jogamp.opengl.GLAutoDrawable;
41import com.jogamp.opengl.GLEventListener;
42import com.jogamp.opengl.GLUniformData;
43import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
52 private int swapInterval = 0;
53 private float aspect = 1.0f;
54 private boolean doRotate =
true;
55 private boolean verbose =
true;
56 private boolean clearBuffers =
true;
58 private boolean doRotateBeforePrinting;
61 this.swapInterval = swapInterval;
65 this.swapInterval = 1;
70 tileRendererInUse = tr;
71 doRotateBeforePrinting = doRotate;
76 tileRendererInUse =
null;
81 System.err.println(
"RedSquareES2.startTileRendering: "+tr);
85 System.err.println(
"RedSquareES2.endTileRendering: "+tr);
88 public void setAspect(
final float aspect) { this.aspect = aspect; }
89 public void setDoRotation(
final boolean rotate) { this.doRotate = rotate; }
96 System.err.println(Thread.currentThread()+
" RedSquareES2.init: tileRendererInUse "+tileRendererInUse);
101 System.err.println(
"RedSquareES2 init on "+Thread.currentThread());
103 System.err.println(
"INIT GL IS: " + gl.getClass().getName());
107 System.err.println(
"No GLSL available, no rendering.");
113 "shader/bin",
"RedSquareShader",
true);
115 "shader/bin",
"RedSquareShader",
true);
119 sp0.
add(gl, vp0, System.err);
120 sp0.
add(gl, fp0, System.err);
131 st.
uniform(gl, pmvMatrixUniform);
135 vertices.
putf(-2); vertices.
putf( 2); vertices.
putf( 0);
136 vertices.
putf( 2); vertices.
putf( 2); vertices.
putf( 0);
137 vertices.
putf(-2); vertices.
putf(-2); vertices.
putf( 0);
138 vertices.
putf( 2); vertices.
putf(-2); vertices.
putf( 0);
139 vertices.
seal(gl,
true);
149 colors.
seal(gl,
true);
157 t0 = System.currentTimeMillis();
159 System.err.println(Thread.currentThread()+
" RedSquareES2.init FIN");
165 final long t1 = System.currentTimeMillis();
169 if(
null != tileRendererInUse ) {
185 final float ang = ((t1 - t0) * 360.0F) / 4000.0F;
189 st.
uniform(gl, pmvMatrixUniform);
204 reshapeImpl(gl, x, y, width, height, width, height);
209 final int tileX,
final int tileY,
final int tileWidth,
final int tileHeight,
210 final int imageWidth,
final int imageHeight) {
213 reshapeImpl(gl, tileX, tileY, tileWidth, tileHeight, imageWidth, imageHeight);
216 void reshapeImpl(
final GL2ES2 gl,
final int tileX,
final int tileY,
final int tileWidth,
final int tileHeight,
final int imageWidth,
final int imageHeight) {
218 System.err.println(Thread.currentThread()+
" RedSquareES2.reshape "+tileX+
"/"+tileY+
" "+tileWidth+
"x"+tileHeight+
" of "+imageWidth+
"x"+imageHeight+
", swapInterval "+swapInterval+
", drawable 0x"+Long.toHexString(gl.
getContext().
getGLDrawable().
getHandle())+
", tileRendererInUse "+tileRendererInUse);
231 final float fovy=45f;
232 final float aspect2 = ( (float) imageWidth / (
float) imageHeight ) / aspect;
233 final float zNear=1f;
234 final float zFar=100f;
237 final float top=(float)Math.tan(fovy*((
float)Math.PI)/360.0f)*zNear;
238 final float bottom=-1.0f*top;
239 final float left=aspect2*bottom;
240 final float right=aspect2*top;
241 final float w = right - left;
242 final float h = top - bottom;
245 final float l = left + tileX * w / imageWidth;
246 final float r = l + tileWidth * w / imageWidth;
247 final float b = bottom + tileY * h / imageHeight;
248 final float t = b + tileHeight * h / imageHeight;
250 pmvMatrix.
glFrustumf(l, r, b, t, zNear, zFar);
252 st.
uniform(gl, pmvMatrixUniform);
255 System.err.println(Thread.currentThread()+
" RedSquareES2.reshape FIN");
261 System.err.println(Thread.currentThread()+
" RedSquareES2.dispose: tileRendererInUse "+tileRendererInUse);
271 System.err.println(Thread.currentThread()+
" RedSquareES2.dispose FIN");
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
abstract GLDrawable getGLDrawable()
Returns the write-drawable this context uses for framebuffer operations.
static StringBuilder getGLStrings(final GL gl, final StringBuilder sb)
void setDoRotation(final boolean rotate)
void display(final GLAutoDrawable glad)
Called by the drawable to initiate OpenGL rendering by the client.
RedSquareES2(final int swapInterval)
void setClearBuffers(final boolean v)
void addTileRendererNotify(final TileRendererBase tr)
The owning GLAutoDrawable is attached to the given TileRendererBase instance.
void setAspect(final float aspect)
void endTileRendering(final TileRendererBase tr)
Called by the TileRenderer during tile-rendering after TileRendererBase#endTile(GL) and GLAutoDrawabl...
void reshapeTile(final TileRendererBase tr, final int tileX, final int tileY, final int tileWidth, final int tileHeight, final int imageWidth, final int imageHeight)
Called by the TileRendererBase during tile-rendering via an attached GLAutoDrawable's GLAutoDrawable#...
RedSquareES2 setVerbose(final boolean v)
void dispose(final GLAutoDrawable glad)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void startTileRendering(final TileRendererBase tr)
Called by the TileRendererBase during tile-rendering after TileRendererBase#beginTile(GL) and before ...
void reshape(final GLAutoDrawable glad, 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 glad)
Called by the drawable immediately after the OpenGL context is initialized.
void removeTileRendererNotify(final TileRendererBase tr)
The owning GLAutoDrawable is detached from the given TileRendererBase instance.
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 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 glFrustumf(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Multiply the current matrix with the frustum matrix.
final void glRotatef(final float ang_deg, final float x, final float y, final float z)
Rotate the current matrix.
final void glLoadIdentity()
Load the current matrix with the identity matrix.
A fairly direct port of Brian Paul's tile rendering library, found at http://www.mesa3d....
final GLAutoDrawable getAttachedDrawable()
Returns a previously attached GLAutoDrawable, null if none is attached.
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.
void setVerbose(final boolean v)
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_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.
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.
GLContext getContext()
Returns the GLContext associated which this GL object.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
long getHandle()
Returns the GL drawable handle, guaranteed to be valid after realization and while it's surface is be...
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_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.