JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TextureSequenceCubeES2.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.test.junit.jogl.demos.es2;
29
30import java.nio.FloatBuffer;
31
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;
58
59public class TextureSequenceCubeES2 implements GLEventListener {
60 public TextureSequenceCubeES2 (final TextureSequence texSource, final boolean innerCube, final float zoom0, final float rotx, final float roty) {
61 this.texSeq = texSource;
62 this.innerCube = innerCube;
63 this.zoom = zoom0;
64 this.view_rotx = rotx;
65 this.view_roty = roty;
66 }
67
68 private TextureSequence texSeq;
71 private GLUniformData pmvMatrixUniform;
72 // private TextureCoords[] textureCoords = null;
73 private float nearPlaneNormalized;
74 // private float zoom0=-5.0f, zoom=zoom0;
75 // private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
76 public float zoom=-2.3f;
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];
80 boolean innerCube;
81
82 private final MouseListener mouseAction = new MouseAdapter() {
83 int lx = 0;
84 int ly = 0;
85 boolean first = false;
86
87 @Override
88 public void mousePressed(final MouseEvent e) {
89 first = true;
90 }
91 @Override
92 public void mouseMoved(final MouseEvent e) {
93 first = false;
94 }
95 @Override
96 public void mouseDragged(final MouseEvent e) {
97 int width, height;
98 final Object source = e.getSource();
99 Window window = null;
100 if(source instanceof Window) {
101 window = (Window) source;
102 width=window.getSurfaceWidth();
103 height=window.getSurfaceHeight();
104 } else if (source instanceof GLAutoDrawable) {
105 final GLAutoDrawable glad = (GLAutoDrawable) source;
106 width = glad.getSurfaceWidth();
107 height = glad.getSurfaceHeight();
108 } else if (GLProfile.isAWTAvailable() && source instanceof java.awt.Component) {
109 final java.awt.Component comp = (java.awt.Component) source;
110 width=comp.getWidth(); // FIXME HiDPI: May need to convert window units -> pixel units!
111 height=comp.getHeight();
112 } else {
113 throw new RuntimeException("Event source neither Window nor Component: "+source);
114 }
115 if(e.getPointerCount()==2) {
116 // 2 pointers zoom ..
117 if(first) {
118 lx = Math.abs(e.getY(0)-e.getY(1));
119 first=false;
120 return;
121 }
122 final int nv = Math.abs(e.getY(0)-e.getY(1));
123 final int dy = nv - lx;
124
125 {
126 final float o = zoom;
127 final float d = 40f*Math.signum(dy)/height;
128 zoom += d;
129 System.err.println("zoom.d: "+o+" + "+d+" -> "+zoom);
130 }
131
132 lx = nv;
133 } else {
134 // 1 pointer rotate
135 if(first) {
136 lx = e.getX();
137 ly = e.getY();
138 first=false;
139 return;
140 }
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 );
145 lx = nx;
146 ly = ny;
147 }
148 }
149 @Override
150 public void mouseWheelMoved(final MouseEvent e) {
151 // System.err.println("XXX "+e);
152 if( !e.isShiftDown() ) {
153 final float o = zoom;
154 final float d = e.getRotation()[1]/10f; // vertical: wheel
155 zoom += d;
156 System.err.println("zoom.w: "+o+" + "+d+" -> "+zoom);
157 }
158 }
159 };
160
161 static final String shaderBasename = "texsequence_xxx";
162 static final String myTextureLookupName = "myTexture2D";
163
164 private void initShader(final GL2ES2 gl) {
165 // Create & Compile the shader objects
166 final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(),
167 "shader", "shader/bin", shaderBasename, true);
168 final ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(),
169 "shader", "shader/bin", shaderBasename, true);
170
171 boolean preludeGLSLVersion = true;
174 throw new GLException(GLExtensions.OES_EGL_image_external+" requested but not available");
175 }
176 if( Platform.OSType.ANDROID == Platform.getOSType() && gl.isGLES3() ) {
177 // Bug on Nexus 10, ES3 - Android 4.3, where
178 // GL_OES_EGL_image_external extension directive leads to a failure _with_ '#version 300 es' !
179 // P0003: Extension 'GL_OES_EGL_image_external' not supported
180 preludeGLSLVersion = false;
181 }
182 }
183 rsVp.defaultShaderCustomization(gl, preludeGLSLVersion, true);
184
185 int rsFpPos = preludeGLSLVersion ? rsFp.addGLSLVersion(gl) : 0;
186 rsFpPos = rsFp.insertShaderSource(0, rsFpPos, texSeq.getRequiredExtensionsShaderStub());
187 rsFp.addDefaultShaderPrecision(gl, rsFpPos);
188
189 final String texLookupFuncName = texSeq.setTextureLookupFunctionName(myTextureLookupName);
190 rsFp.replaceInShaderSource(myTextureLookupName, texLookupFuncName);
191
192 // Inject TextureSequence shader details
193 final StringBuilder sFpIns = new StringBuilder();
194 sFpIns.append("uniform ").append(texSeq.getTextureSampler2DType()).append(" mgl_ActiveTexture;\n");
195 sFpIns.append(texSeq.getTextureLookupFragmentShaderImpl());
196 rsFp.insertShaderSource(0, "TEXTURE-SEQUENCE-CODE-BEGIN", 0, sFpIns);
197
198 // Create & Link the shader program
199 final ShaderProgram sp = new ShaderProgram();
200 sp.add(rsVp);
201 sp.add(rsFp);
202 if(!sp.link(gl, System.err)) {
203 throw new GLException("Couldn't link program: "+sp);
204 }
205
206 // Let's manage all our states using ShaderState.
207 st = new ShaderState();
208 st.attachShaderProgram(gl, sp, false);
209 }
210
211 GLArrayDataServer interleavedVBO, cubeIndicesVBO;
212
213 @Override
214 public void init(final GLAutoDrawable drawable) {
215 final GL2ES2 gl = drawable.getGL().getGL2ES2();
216 System.err.println(JoglVersion.getGLInfo(gl, null));
217 final TextureFrame frame = texSeq.getLastTexture();
218 if( null == frame ) {
219 return;
220 }
221 final Texture tex= frame.getTexture();
222
223 initShader(gl);
224
225 // Push the 1st uniform down the path
226 st.useProgram(gl, true);
227
228 pmvMatrix = new PMVMatrix();
229 reshapePMV(drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
230 pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.getSyncPMv()); // P, Mv
231 if(!st.uniform(gl, pmvMatrixUniform)) {
232 throw new GLException("Error setting PMVMatrix in shader: "+st);
233 }
234 if(!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", texSeq.getTextureUnit()))) {
235 throw new GLException("Error setting mgl_ActiveTexture in shader: "+st);
236 }
237
238
239 // calculate centered tex coords w/ aspect ratio
240 final float[] fixedCubeTexCoords = new float[s_cubeTexCoords.length];
241 {
242 final float aspect = tex.getAspectRatio();
243 final TextureCoords tc = tex.getImageTexCoords();
244 System.err.println("XXX0: aspect: "+aspect);
245 System.err.println("XXX0: y-flip: "+tex.getMustFlipVertically());
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; // scale tex-coord
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];
254 if(tx!=0) {
255 fixedCubeTexCoords[i+0] = tc_x1 * ss;
256 }
257 if(ty==0 && !tex.getMustFlipVertically() || ty!=0 && tex.getMustFlipVertically()) {
258 fixedCubeTexCoords[i+1] = 0f + dy;
259 } else {
260 fixedCubeTexCoords[i+1] = tc_y1 * ts + dy;
261 }
262 }
263 }
264
265 interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3+4+2, GL.GL_FLOAT, false, 3*6*4, GL.GL_STATIC_DRAW);
266 {
267 interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER);
268 interleavedVBO.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER);
269 //interleavedVBO.addGLSLSubArray("mgl_Normal", 3, GL.GL_ARRAY_BUFFER);
270 interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER);
271
272 final FloatBuffer ib = (FloatBuffer)interleavedVBO.getBuffer();
273
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);
277 //ib.put(s_cubeNormals, i*3, 3);
278 ib.put(fixedCubeTexCoords, i*2, 2);
279 }
280 }
281 interleavedVBO.seal(gl, true);
282 interleavedVBO.enableBuffer(gl, false);
283 st.ownAttribute(interleavedVBO, true);
284
286 for(int i=0; i<6*6; i++) {
287 cubeIndicesVBO.puts(s_cubeIndices[i]);
288 }
289 cubeIndicesVBO.seal(gl, true);
290 cubeIndicesVBO.enableBuffer(gl, false);
291 st.ownAttribute(cubeIndicesVBO, true);
292
293
295
296 st.useProgram(gl, false);
297
298 final Object upstreamWidget = drawable.getUpstreamWidget();
299 if (upstreamWidget instanceof Window) {
300 final Window window = (Window) upstreamWidget;
301 window.addMouseListener(mouseAction);
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);
305 }
306
307 // Let's show the completed shader state ..
308 System.out.println("iVBO: "+interleavedVBO);
309 System.out.println(st);
310 }
311
312 @Override
313 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
314 final GL2ES2 gl = drawable.getGL().getGL2ES2();
315
316 gl.glViewport(0, 0, width, height);
317
318 if(!innerCube) {
319 // lights on
320 } else {
321 // lights off
322 }
323 // gl.glEnable(GL.GL_CULL_FACE);
324 // gl.glDisable(GL.GL_DITHER);
325
326 if(null != st) {
327 reshapePMV(width, height);
328 st.useProgram(gl, true);
329 st.uniform(gl, pmvMatrixUniform);
330 st.useProgram(gl, false);
331 }
332 }
333
334
335 private void reshapePMV(final int width, final int height) {
336 if(null != pmvMatrix) {
339 if(!innerCube) {
340 pmvMatrix.gluPerspective(FloatUtil.QUARTER_PI, (float)width / (float)height, 1f, 10.0f);
341 nearPlaneNormalized = 1f/(100f-1f);
342 } else {
343 pmvMatrix.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 10.0f);
344 nearPlaneNormalized = 0f;
345 }
346 System.err.println("XXX0: Perspective nearPlaneNormalized: "+nearPlaneNormalized);
347
348 pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
351 }
352 }
353
354
355 @Override
356 public void dispose(final GLAutoDrawable drawable) {
357 final GL2ES2 gl = drawable.getGL().getGL2ES2();
358
359 texSeq = null;
360 pmvMatrixUniform = null;
361 pmvMatrix=null;
362 if( null != st ) {
363 st.destroy(gl);
364 st=null;
365 }
366 }
367
368 @Override
369 public void display(final GLAutoDrawable drawable) {
370 final GL2ES2 gl = drawable.getGL().getGL2ES2();
371
372 if(innerCube) {
373 // Clear background to white
374 gl.glClearColor(1.0f, 1.0f, 1.0f, 0.4f);
375 } else {
376 // Clear background to blue
377 gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
378 }
380
381 if( null == st ) {
382 return;
383 }
384
385 st.useProgram(gl, true);
386
390 pmvMatrix.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
391 pmvMatrix.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
392 pmvMatrix.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
393 st.uniform(gl, pmvMatrixUniform);
394 interleavedVBO.enableBuffer(gl, true);
395 Texture tex = null;
396 if(null!=texSeq) {
397 final TextureSequence.TextureFrame texFrame = texSeq.getNextTexture(gl);
398 if(null != texFrame) {
399 tex = texFrame.getTexture();
401 tex.enable(gl);
402 tex.bind(gl);
403 }
404 }
405 cubeIndicesVBO.bindBuffer(gl, true); // keeps VBO binding
406 gl.glDrawElements(GL.GL_TRIANGLES, cubeIndicesVBO.getElemCount() * cubeIndicesVBO.getCompsPerElem(), GL.GL_UNSIGNED_SHORT, 0);
407 cubeIndicesVBO.bindBuffer(gl, false);
408
409 if(null != tex) {
410 tex.disable(gl);
411 }
412 interleavedVBO.enableBuffer(gl, false);
413 st.useProgram(gl, false);
414 }
415
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 };
421
422 private static final float[] s_cubeVertices = /* f b t b r l */
423 {
424 -1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, 1f, -1f, -1f, 1f,
425
426 -1f, 1f, -1f, 1f, -1f, -1f, 1f, 1f, -1f, -1f, -1f, -1f,
427
428 -1f, -1f, 1f, 1f, -1f, -1f, 1f, -1f, 1f, -1f, -1f, -1f,
429
430 -1f, 1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, -1f, 1f, -1f,
431
432 1f, -1f, 1f, 1f, 1f, -1f, 1f, 1f, 1f, 1f, -1f, -1f,
433
434 -1f, -1f, 1f, -1f, 1f, -1f, -1f, 1f, 1f, -1f, -1f, -1f
435 };
436
437 private static final float[] s_cubeTexCoords =
438 { // LT RB RT LB
439 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f,
440
441 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f,
442
443 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f,
444
445 0f, 1f, 1f, 0f, 1f, 1f, 0f, 0f,
446
447 0f, 0f, 1f, 1f, 0f, 1f, 1f, 0f,
448
449 0f, 0f, 1f, 1f, 0f, 1f, 1f, 0f,
450 };
451
452 private static final float[] s_cubeColors =
453 {
454 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f,
455
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,
458
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,
461
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,
464
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,
467
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
470 };
471
472 /*
473 private static final float[] s_cubeNormals =
474 {
475 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f,
476
477 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f,
478
479 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f,
480
481 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f,
482
483 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f, 1f, 0f, 0f,
484
485 -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f, -1f, 0f, 0f
486 };*/
487 private static final short[] s_cubeIndices =
488 {
489 0, 3, 1, 2, 0, 1, /* front */
490 6, 5, 4, 5, 7, 4, /* back */
491 8, 11, 9, 10, 8, 9, /* top */
492 15, 12, 13, 12, 14, 13, /* bottom */
493 16, 19, 17, 18, 16, 17, /* right */
494 23, 20, 21, 20, 22, 21 /* left */
495 };
496}
497
Basic Float math utility functions.
Definition: FloatUtil.java:83
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.
final boolean isShiftDown()
getModifiers() contains SHIFT_MASK.
Pointer event of type PointerType.
Definition: MouseEvent.java:74
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.
Definition: GLProfile.java:77
GLSL uniform data wrapper encapsulating data to be uploaded to the GPU as a uniform.
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.
Definition: PMVMatrix.java:62
final void glTranslatef(final float x, final float y, final float z)
Translate the current matrix.
Definition: PMVMatrix.java:379
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
Definition: PMVMatrix.java:218
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.
Definition: PMVMatrix.java:469
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.
Definition: PMVMatrix.java:499
final void glRotatef(final float ang_deg, final float x, final float y, final float z)
Rotate the current matrix.
Definition: PMVMatrix.java:413
final void glLoadIdentity()
Load the current matrix with the identity matrix.
Definition: PMVMatrix.java:325
Convenient shader code class to use and instantiate vertex or fragment programs.
Definition: ShaderCode.java:75
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.
Represents an OpenGL texture object.
Definition: Texture.java:173
TextureCoords getImageTexCoords()
Returns the set of texture coordinates corresponding to the entire image.
Definition: Texture.java:480
void bind(final GL gl)
Binds this texture to the given GL context.
Definition: Texture.java:377
boolean getMustFlipVertically()
Indicates whether this texture's texture coordinates must be flipped vertically in order to properly ...
Definition: Texture.java:536
void disable(final GL gl)
Disables this texture's target (e.g., GL_TEXTURE_2D) in the given GL state.
Definition: Texture.java:357
float getAspectRatio()
Returns the original aspect ratio of the image, defined as (image width) / (image height),...
Definition: Texture.java:468
void enable(final GL gl)
Enables this texture's target (e.g., GL_TEXTURE_2D) in the given GL context's state.
Definition: Texture.java:330
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:
Definition: Window.java:115
void addMouseListener(MouseListener l)
Appends the given MouseListener to the end of the list.
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...
Definition: GL2ES2.java:39
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...
Definition: GL2ES2.java:541
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',...
Definition: GLES2.java:57
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...
Definition: GL.java:673
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...
Definition: GL.java:145
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...
Definition: GL.java:786
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 ...
Definition: GL.java:346
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...
Definition: GL.java:390
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...
Definition: GL.java:43
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 ...
Definition: GL.java:71
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...
Definition: GL.java:738
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...
Definition: GL.java:318
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...
Definition: GL.java:633
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,...