JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
NEWTGearsES2Activity.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 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.demos.android;
29
30import java.nio.Buffer;
31import java.nio.ByteBuffer;
32import java.util.ArrayList;
33
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLProfile;
36import com.jogamp.opengl.demos.es2.GearsES2;
37
38import jogamp.newt.driver.android.NewtBaseActivity;
39
40import com.jogamp.common.util.InterruptSource;
41import com.jogamp.newt.event.MonitorEvent;
42import com.jogamp.newt.event.MouseAdapter;
43import com.jogamp.newt.event.MouseEvent;
44import com.jogamp.newt.event.MonitorModeListener;
45import com.jogamp.newt.opengl.GLWindow;
46
47import com.jogamp.opengl.util.Animator;
48
49import android.os.Bundle;
50import android.util.Log;
51
52public class NEWTGearsES2Activity extends NewtBaseActivity {
53 static String TAG = "NEWTGearsES2Activity";
54
55 static final String forceRGBA5650 = "demo.force.rgba5650";
56 static final String forceECT = "demo.force.ect";
57 static final String forceKillProcessTest = "demo.force.killProcessTest";
58
59 @Override
60 public void onCreate(final Bundle savedInstanceState) {
61 Log.d(TAG, "onCreate - 0");
62 super.onCreate(savedInstanceState);
63
64 // create GLWindow (-> incl. underlying NEWT Display, Screen & Window)
66 if( null != System.getProperty(forceRGBA5650) ) {
67 Log.d(TAG, "forceRGBA5650");
68 caps.setRedBits(5); caps.setGreenBits(6); caps.setBlueBits(5);
69 }
70
71 Log.d(TAG, "req caps: "+caps);
72 final GLWindow glWindow = GLWindow.create(caps);
73 glWindow.setFullscreen(true);
74 setContentView(getWindow(), glWindow);
75
76 final GearsES2 demo = new GearsES2(-1);
77 // demo.enableAndroidTrace(true);
78 glWindow.addGLEventListener(demo);
80 @Override
81 public void monitorModeChangeNotify(final MonitorEvent me) { }
82 @Override
83 public void monitorModeChanged(final MonitorEvent me, final boolean success) {
84 System.err.println("MonitorMode Changed (success "+success+"): "+me);
85 }
86 });
87 if( null != System.getProperty(forceKillProcessTest) ) {
88 Log.d(TAG, "forceKillProcessTest");
89 glWindow.addMouseListener(new MouseAdapter() {
90 @Override
91 public void mousePressed(final MouseEvent e) {
92 if( e.getPointerCount() == 3 ) {
93 Log.d(TAG, "MemoryHog");
94 new InterruptSource.Thread(null, new Runnable() {
95 @Override
96 public void run() {
97 final ArrayList<Buffer> buffers = new ArrayList<Buffer>();
98 while(true) {
99 final int halfMB = 512 * 1024;
100 final float osizeMB = buffers.size() * 0.5f;
101 final float nsizeMB = osizeMB + 0.5f;
102 System.err.println("MemoryHog: ****** +4k: "+osizeMB+" MB +"+nsizeMB+" MB - Try");
103 buffers.add(ByteBuffer.allocateDirect(halfMB)); // 0.5 MB each
104 System.err.println("MemoryHog: ****** +4k: "+osizeMB+" MB +"+nsizeMB+" MB - Done");
105 try {
106 Thread.sleep(500);
107 } catch (final Exception e) { e.printStackTrace(); };
108 }
109 } }, "MemoryHog").start();
110 } else if( e.getPointerCount() == 4 ) {
111 Log.d(TAG, "ForceKill");
112 android.os.Process.killProcess( android.os.Process.myPid() );
113 }
114 }
115 });
116 }
117 final Animator animator = new Animator(glWindow);
118 // animator.setRunAsFastAsPossible(true);
119 // glWindow.setSkipContextReleaseThread(animator.getThread());
120
121 if( null != System.getProperty(forceECT) ) {
122 Log.d(TAG, "forceECT");
123 animator.setExclusiveContext(true);
124 }
125
126 glWindow.setVisible(true);
127
128 animator.setUpdateFPSFrames(60, System.err);
129 animator.resetFPSCounter();
130 glWindow.resetFPSCounter();
131
132 Log.d(TAG, "onCreate - X");
133 }
134}
void setRedBits(final int redBits)
Sets the number of bits requested for the color buffer's red component.
void setGreenBits(final int greenBits)
Sets the number of bits requested for the color buffer's green component.
void setBlueBits(final int blueBits)
Sets the number of bits requested for the color buffer's blue component.
abstract void addMonitorModeListener(MonitorModeListener sml)
Pointer event of type PointerType.
Definition: MouseEvent.java:74
final int getPointerCount()
See details for multiple-pointer events.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
Definition: GLWindow.java:927
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
Definition: GLWindow.java:534
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
final void resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
final synchronized Thread setExclusiveContext(final Thread t)
Dedicate all GLAutoDrawable's context to the given exclusive context thread.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
void resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.