28package com.jogamp.opengl.test.junit.jogl.demos.es2;
30import java.nio.FloatBuffer;
32import com.jogamp.opengl.GL;
33import com.jogamp.opengl.GL2ES2;
34import com.jogamp.opengl.GLAutoDrawable;
35import com.jogamp.opengl.GLES2;
36import com.jogamp.opengl.GLEventListener;
37import com.jogamp.opengl.GLException;
38import com.jogamp.opengl.GLProfile;
39import com.jogamp.opengl.GLUniformData;
40import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
41import com.jogamp.common.os.Platform;
42import com.jogamp.math.FloatUtil;
43import com.jogamp.newt.Window;
44import com.jogamp.newt.event.MouseAdapter;
45import com.jogamp.newt.event.MouseEvent;
46import com.jogamp.newt.event.MouseListener;
47import com.jogamp.opengl.GLExtensions;
48import com.jogamp.opengl.JoglVersion;
49import com.jogamp.opengl.util.GLArrayDataServer;
50import com.jogamp.opengl.util.PMVMatrix;
51import com.jogamp.opengl.util.glsl.ShaderCode;
52import com.jogamp.opengl.util.glsl.ShaderProgram;
53import com.jogamp.opengl.util.glsl.ShaderState;
54import com.jogamp.opengl.util.texture.Texture;
55import com.jogamp.opengl.util.texture.TextureCoords;
56import com.jogamp.opengl.util.texture.TextureSequence;
57import com.jogamp.opengl.util.texture.TextureSequence.TextureFrame;
61 this.texSeq = texSource;
62 this.innerCube = innerCube;
64 this.view_rotx = rotx;
65 this.view_roty = roty;
73 private float nearPlaneNormalized;
77 private float view_rotx = 0.0f, view_roty = 0.0f;
78 private final float view_rotz = 0.0f;
79 int[] vboNames =
new int[4];
85 boolean first =
false;
98 final Object source = e.getSource();
100 if(source instanceof
Window) {
108 }
else if (
GLProfile.isAWTAvailable() && source instanceof java.awt.Component) {
109 final java.awt.Component comp = (java.awt.Component) source;
110 width=comp.getWidth();
111 height=comp.getHeight();
113 throw new RuntimeException(
"Event source neither Window nor Component: "+source);
122 final int nv = Math.abs(e.
getY(0)-e.
getY(1));
123 final int dy = nv - lx;
126 final float o =
zoom;
127 final float d = 40f*Math.signum(dy)/height;
129 System.err.println(
"zoom.d: "+o+
" + "+d+
" -> "+
zoom);
141 final int nx = e.
getX();
142 final int ny = e.
getY();
143 view_roty += 360f * ( (float)( nx - lx ) / (float)width );
144 view_rotx += 360f * ( (float)( ny - ly ) / (float)height );
150 public void mouseWheelMoved(
final MouseEvent e) {
153 final float o =
zoom;
156 System.err.println(
"zoom.w: "+o+
" + "+d+
" -> "+
zoom);
161 static final String shaderBasename =
"texsequence_xxx";
162 static final String myTextureLookupName =
"myTexture2D";
164 private void initShader(
final GL2ES2 gl) {
167 "shader",
"shader/bin", shaderBasename,
true);
169 "shader",
"shader/bin", shaderBasename,
true);
171 boolean preludeGLSLVersion =
true;
176 if( Platform.OSType.ANDROID == Platform.getOSType() && gl.
isGLES3() ) {
180 preludeGLSLVersion =
false;
193 final StringBuilder sFpIns =
new StringBuilder();
199 final ShaderProgram sp =
new ShaderProgram();
202 if(!sp.link(gl, System.err)) {
203 throw new GLException(
"Couldn't link program: "+sp);
207 st =
new ShaderState();
211 GLArrayDataServer interleavedVBO, cubeIndicesVBO;
218 if(
null == frame ) {
232 throw new GLException(
"Error setting PMVMatrix in shader: "+
st);
235 throw new GLException(
"Error setting mgl_ActiveTexture in shader: "+
st);
240 final float[] fixedCubeTexCoords =
new float[s_cubeTexCoords.length];
244 System.err.println(
"XXX0: aspect: "+aspect);
246 System.err.println(
"XXX0: "+tc);
247 final float tc_x1 = Math.max(tc.left(), tc.right());
248 final float tc_y1 = Math.max(tc.bottom(), tc.top());
249 final float ss=1f, ts=aspect;
250 final float dy = ( 1f - aspect ) / 2f ;
251 for(
int i=0; i<s_cubeTexCoords.length; i+=2) {
252 final float tx = s_cubeTexCoords[i+0];
253 final float ty = s_cubeTexCoords[i+1];
255 fixedCubeTexCoords[i+0] = tc_x1 * ss;
258 fixedCubeTexCoords[i+1] = 0f + dy;
260 fixedCubeTexCoords[i+1] = tc_y1 * ts + dy;
272 final FloatBuffer ib = (FloatBuffer)interleavedVBO.
getBuffer();
274 for(
int i=0; i<6*4; i++) {
275 ib.put(s_cubeVertices, i*3, 3);
276 ib.put(s_cubeColors, i*4, 4);
278 ib.put(fixedCubeTexCoords, i*2, 2);
281 interleavedVBO.seal(gl,
true);
282 interleavedVBO.enableBuffer(gl,
false);
286 for(
int i=0; i<6*6; i++) {
287 cubeIndicesVBO.
puts(s_cubeIndices[i]);
289 cubeIndicesVBO.seal(gl,
true);
290 cubeIndicesVBO.enableBuffer(gl,
false);
299 if (upstreamWidget instanceof
Window) {
302 }
else if (
GLProfile.isAWTAvailable() && upstreamWidget instanceof java.awt.Component) {
303 final java.awt.Component comp = (java.awt.Component) upstreamWidget;
304 new com.jogamp.newt.event.awt.AWTMouseAdapter(mouseAction, drawable).addTo(comp);
308 System.out.println(
"iVBO: "+interleavedVBO);
309 System.out.println(
st);
327 reshapePMV(width, height);
335 private void reshapePMV(
final int width,
final int height) {
341 nearPlaneNormalized = 1f/(100f-1f);
344 nearPlaneNormalized = 0f;
346 System.err.println(
"XXX0: Perspective nearPlaneNormalized: "+nearPlaneNormalized);
360 pmvMatrixUniform =
null;
394 interleavedVBO.enableBuffer(gl,
true);
397 final TextureSequence.TextureFrame texFrame = texSeq.
getNextTexture(gl);
398 if(
null != texFrame) {
399 tex = texFrame.getTexture();
405 cubeIndicesVBO.bindBuffer(gl,
true);
407 cubeIndicesVBO.bindBuffer(gl,
false);
412 interleavedVBO.enableBuffer(gl,
false);
416 static final float[] light_position = { -50.f, 50.f, 50.f, 0.f };
417 static final float[] light_ambient = { 0.125f, 0.125f, 0.125f, 1.f };
418 static final float[] light_diffuse = { 1.0f, 1.0f, 1.0f, 1.f };
419 static final float[] material_spec = { 1.0f, 1.0f, 1.0f, 0.f };
420 static final float[] zero_vec4 = { 0.0f, 0.0f, 0.0f, 0.f };
422 private static final float[] s_cubeVertices =
424 -1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, 1f, -1f, -1f, 1f,
426 -1f, 1f, -1f, 1f, -1f, -1f, 1f, 1f, -1f, -1f, -1f, -1f,
428 -1f, -1f, 1f, 1f, -1f, -1f, 1f, -1f, 1f, -1f, -1f, -1f,
430 -1f, 1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, -1f, 1f, -1f,
432 1f, -1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, 1f, -1f, -1f,
434 -1f, -1f, 1f, -1f, 1f, -1f, -1f, 1f, 1f, -1f, -1f, -1f
437 private static final float[] s_cubeTexCoords =
439 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f,
441 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f,
443 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f,
445 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f,
447 0f, 0f, 1f, 1f, 0f, 1f, 1f, 0f,
449 0f, 0f, 1f, 1f, 0f, 1f, 1f, 0f,
452 private static final float[] s_cubeColors =
454 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f,
456 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
457 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
459 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
460 40f/255f, 80f/255f, 160f/255f, 255f/255f, 40f/255f, 80f/255f, 160f/255f, 255f/255f,
462 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
463 128f/255f, 128f/255f, 128f/255f, 255f/255f, 128f/255f, 128f/255f, 128f/255f, 255f/255f,
465 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f,
466 255f/255f, 110f/255f, 10f/255f, 255f/255f, 255f/255f, 110f/255f, 10f/255f, 255f/255f,
468 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255f/255f,
469 255f/255f, 70f/255f, 60f/255f, 255f/255f, 255f/255f, 70f/255f, 60f/255f, 255f/255f
487 private static final short[] s_cubeIndices =
492 15, 12, 13, 12, 14, 13,
493 16, 19, 17, 18, 16, 17,
494 23, 20, 21, 20, 22, 21
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.
Pointer event of type PointerType.
final int getPointerCount()
See details for multiple-pointer events.
final int getY()
See details for multiple-pointer events.
final float[] getRotation()
Returns a 3-component float array filled with the values of the rotational axis in the following orde...
final int getX()
See details for multiple-pointer events.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Class holding OpenGL extension strings, commonly used by JOGL's implementation.
static final String OES_EGL_image_external
Specifies the the OpenGL profile.
static StringBuilder getGLInfo(final GL gl, final StringBuilder sb)
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 dispose(final GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
TextureSequenceCubeES2(final TextureSequence texSource, final boolean innerCube, final float zoom0, final float rotx, final float roty)
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
static GLArrayDataServer createGLSLInterleaved(final int compsPerElement, final int dataType, final boolean normalized, final int initialElementCount, final int vboUsage)
Create a VBO for GLSL interleaved array data starting with a new created Buffer object with initialEl...
static GLArrayDataServer createData(final int compsPerElement, final int dataType, final int stride, final Buffer buffer, final int vboUsage, final int vboTarget)
Create a VBO data object for any target w/o render pipeline association, ie GL#GL_ELEMENT_ARRAY_BUFFE...
GLArrayDataWrapper addGLSLSubArray(final String name, final int comps, final int vboTarget)
Configure a segment of this GLSL interleaved array (see createGLSLInterleaved(int,...
Buffer getBuffer()
The Buffer holding the data, may be null if a GPU buffer without client bound data.
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 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 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 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.
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.
final int addGLSLVersion(final GL2ES2 gl)
Add GLSL version at the head 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 replaceInShaderSource(final String oldName, final String newName)
Replaces oldName with newName in all shader sources.
final int addDefaultShaderPrecision(final GL2ES2 gl, int pos)
Adds default precision to source code at given position if required, i.e.
int insertShaderSource(final int shaderIdx, final String tag, final int fromIndex, final CharSequence data)
Adds data after the line containing tag.
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.
Specifies texture coordinates for a rectangular area of a texture.
Texture holder interface, maybe specialized by implementation to associated related data.
final Texture getTexture()
Represents an OpenGL texture object.
TextureCoords getImageTexCoords()
Returns the set of texture coordinates corresponding to the entire image.
void bind(final GL gl)
Binds this texture to the given GL context.
boolean getMustFlipVertically()
Indicates whether this texture's texture coordinates must be flipped vertically in order to properly ...
void disable(final GL gl)
Disables this texture's target (e.g., GL_TEXTURE_2D) in the given GL state.
float getAspectRatio()
Returns the original aspect ratio of the image, defined as (image width) / (image height),...
void enable(final GL gl)
Enables this texture's target (e.g., GL_TEXTURE_2D) in the given GL context's state.
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.
Specifying NEWT's Window functionality:
void addMouseListener(MouseListener l)
Appends the given MouseListener to the end of the list.
Listener for MouseEvents.
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.
Object getUpstreamWidget()
Method may return the upstream UI toolkit object holding this GLAutoDrawable instance,...
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
boolean isExtensionAvailable(String glExtensionName)
Returns true if the specified OpenGL extension can be used successfully through this GL instance give...
boolean isGLES3()
Indicates whether this GL object conforms to the OpenGL ES ≥ 3.0 profile.
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_TEXTURE_EXTERNAL_OES
GL_OES_EGL_image_external Define "GL_TEXTURE_EXTERNAL_OES" with expression '0x8D65',...
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
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_TRIANGLES
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TRIANGLES" with expre...
void glDrawElements(int mode, int count, int type, long indices_buffer_offset)
Entry point to C language function: void {@native glDrawElements}(GLenum mode, GLsizei count,...
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_UNSIGNED_SHORT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_UNSIGNED_SHORT" with ...
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 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 glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
static final int GL_TEXTURE0
GL_ES_VERSION_2_0, GL_VERSION_1_3, GL_VERSION_ES_1_0, GL_ARB_multitexture Alias for: GL_TEXTURE0_ARB ...
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...
static final int GL_ELEMENT_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ELEME...
static final int GL_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ARRAY...
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.
Protocol for texture sequences, like animations, movies, etc.
TextureFrame getLastTexture()
Returns the last updated texture.
int getTextureTarget()
Returns the texture target used by implementation.
String getTextureLookupFragmentShaderImpl()
Returns the complete texture2D lookup function code of type.
String getTextureSampler2DType()
Returns either sampler2D or samplerExternalOES depending on getLastTexture().
String setTextureLookupFunctionName(String texLookupFuncName)
Set the desired shader code's texture lookup function name.
int getTextureUnit()
Return the texture unit used to render the current frame.
TextureFrame getNextTexture(GL gl)
Returns the next texture to be rendered.
String getRequiredExtensionsShaderStub()
In case a shader extension is required, based on the implementation and the runtime GL profile,...