Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Multiple Monitors in jme-LWJGL3 #2030 #2031

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
acd2cb3
Add support for Multiple Monitors in jme-LWJGL3 #2030
bob0bob Jun 5, 2023
94fb53b
Add support for Multiple Monitors in jme-LWJGL3 #2030
bob0bob Jun 5, 2023
2251e2e
updated comment and change comment on default value to 0.
bob0bob Jun 8, 2023
75f6d66
By default use PrimitiveAllocator on Android (#2029) (#6)
bob0bob Jun 8, 2023
8ef3c5e
Missed a file during check in for multiple monitor selection.
bob0bob Jun 8, 2023
6a590db
Changing formatting to be google format style for the JME standard.
bob0bob Jun 14, 2023
8594c1d
renamed monitor data into generic form of Display for compatibility …
bob0bob Sep 22, 2023
03dd250
Revert "renamed monitor data into generic form of Display for compat…
bob0bob Sep 22, 2023
7050d7a
renamed monitor data into generic form of Display for compatibility …
bob0bob Sep 22, 2023
48a7980
Revert "renamed monitor data into generic form of Display for compat…
bob0bob Sep 23, 2023
8088109
Merge branch 'master' of https://github.com/bob0bob/jmonkeyengine
bob0bob Sep 23, 2023
be6624e
Merge branch 'master' of https://github.com/bob0bob/jmonkeyengine
bob0bob Sep 23, 2023
35e8857
auto-format
bob0bob Sep 23, 2023
1bda3f0
merging new files.
bob0bob Sep 23, 2023
d8d827b
Revert "merging new files."
bob0bob Sep 23, 2023
8ddb04b
changing naming to "Display" instead of "Monitor"
bob0bob Sep 23, 2023
2f39669
auto-format
bob0bob Sep 23, 2023
7010af6
When merging into the main branch, I update a file I should not have …
bob0bob Sep 24, 2023
5445d3f
Merge branch 'master' of https://github.com/bob0bob/jmonkeyengine
bob0bob Sep 24, 2023
f25ce69
forgot to remove old classes that got renamed to Displays
bob0bob Nov 1, 2023
7dd8693
Merge branch 'jMonkeyEngine:master' into master
bob0bob Nov 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 139 additions & 91 deletions jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import com.jme3.system.*;
import com.jme3.util.BufferAllocatorFactory;
import com.jme3.util.PrimitiveAllocator;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -79,7 +78,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
protected SystemListener listener;
protected boolean autoFlush = true;
protected AndroidInputHandler androidInput;
protected long minFrameDuration = 0; // No FPS cap
protected long minFrameDuration = 0; // No FPS cap
protected long lastUpdateTime = 0;

static {
Expand All @@ -90,8 +89,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
}
}

public OGLESContext() {
}
public OGLESContext() {}

@Override
public Type getType() {
Expand All @@ -115,9 +113,11 @@ public GLSurfaceView createView(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// below 4.0, check OpenGL ES 2.0 support.
if (info.reqGlEsVersion < 0x20000) {
throw new UnsupportedOperationException("OpenGL ES 2.0 or better is not supported on this device");
throw new UnsupportedOperationException(
"OpenGL ES 2.0 or better is not supported on this device"
);
}
} else if (Build.VERSION.SDK_INT < 9){
} else if (Build.VERSION.SDK_INT < 9) {
throw new UnsupportedOperationException("jME3 requires Android 2.3 or later");
}

Expand All @@ -127,7 +127,7 @@ public GLSurfaceView createView(Context context) {
if (androidInput == null) {
if (Build.VERSION.SDK_INT >= 14) {
androidInput = new AndroidInputHandler14();
} else if (Build.VERSION.SDK_INT >= 9){
} else if (Build.VERSION.SDK_INT >= 9) {
androidInput = new AndroidInputHandler();
}
}
Expand All @@ -137,7 +137,7 @@ public GLSurfaceView createView(Context context) {
// setEGLContextClientVersion must be set before calling setRenderer
// this means it cannot be set in AndroidConfigChooser (too late)
// use proper openGL ES version
view.setEGLContextClientVersion(info.reqGlEsVersion>>16);
view.setEGLContextClientVersion(info.reqGlEsVersion >> 16);

view.setFocusableInTouchMode(true);
view.setFocusable(true);
Expand Down Expand Up @@ -200,22 +200,35 @@ protected void initInThread() {
logger.log(Level.FINE, "Running on thread: {0}", Thread.currentThread().getName());

// Setup unhandled Exception Handler
Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable thrown) {
listener.handleError("Exception thrown in " + thread.toString(), thrown);
}
});
Thread
.currentThread()
.setUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable thrown) {
listener.handleError("Exception thrown in " + thread.toString(), thrown);
}
}
);

timer = new NanoTimer();
GL gl = new AndroidGL();
if (settings.getBoolean("GraphicsDebug")) {
gl = (GL) GLDebug.createProxy(gl, gl, GL.class, GL2.class, GLES_30.class, GLFbo.class, GLExt.class);
gl =
(GL) GLDebug.createProxy(
gl,
gl,
GL.class,
GL2.class,
GLES_30.class,
GLFbo.class,
GLExt.class
);
}
if (settings.getBoolean("GraphicsTrace")) {
gl = (GL)GLTracer.createGlesTracer(gl, GL.class, GLES_30.class, GLFbo.class, GLExt.class);
gl = (GL) GLTracer.createGlesTracer(gl, GL.class, GLES_30.class, GLFbo.class, GLExt.class);
}
renderer = new GLRenderer(gl, (GLExt)gl, (GLFbo)gl);
renderer = new GLRenderer(gl, (GLExt) gl, (GLFbo) gl);
renderer.initialize();

JmeSystem.setSoftTextDialogInput(this);
Expand Down Expand Up @@ -254,7 +267,7 @@ public void setSettings(AppSettings settings) {
}

if (settings.getFrameRate() > 0) {
minFrameDuration = (long)(1000d / settings.getFrameRate()); // ms
minFrameDuration = (long) (1000d / settings.getFrameRate()); // ms
logger.log(Level.FINE, "Setting min tpf: {0}ms", minFrameDuration);
} else {
minFrameDuration = 0;
Expand Down Expand Up @@ -312,8 +325,7 @@ public Timer getTimer() {
}

@Override
public void setTitle(String title) {
}
public void setTitle(String title) {}

@Override
public boolean isCreated() {
Expand All @@ -329,7 +341,11 @@ public void setAutoFlushFrames(boolean enabled) {
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "GL Surface changed, width: {0} height: {1}", new Object[]{width, height});
logger.log(
Level.FINE,
"GL Surface changed, width: {0} height: {1}",
new Object[] { width, height }
);
}
// update the application settings with the new resolution
settings.setResolution(width, height);
Expand Down Expand Up @@ -372,16 +388,14 @@ public void onDrawFrame(GL10 gl) {

// Enforce a FPS cap
if (updateDelta < minFrameDuration) {
// logger.log(Level.INFO, "lastUpdateTime: {0}, updateDelta: {1}, minTimePerFrame: {2}",
// new Object[]{lastUpdateTime, updateDelta, minTimePerFrame});
// logger.log(Level.INFO, "lastUpdateTime: {0}, updateDelta: {1}, minTimePerFrame: {2}",
// new Object[]{lastUpdateTime, updateDelta, minTimePerFrame});
try {
Thread.sleep(minFrameDuration - updateDelta);
} catch (InterruptedException e) {
}
} catch (InterruptedException e) {}
}

lastUpdateTime = System.currentTimeMillis();

}
}

Expand All @@ -402,8 +416,7 @@ public void create() {
}

@Override
public void restart() {
}
public void restart() {}

@Override
public void destroy(boolean waitFor) {
Expand All @@ -421,76 +434,99 @@ protected void waitFor(boolean createdVal) {
while (renderable.get() != createdVal) {
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
}
} catch (InterruptedException ex) {}
}
}

@Override
public void requestDialog(final int id, final String title, final String initialValue, final SoftTextDialogInputListener listener) {
public void requestDialog(
final int id,
final String title,
final String initialValue,
final SoftTextDialogInputListener listener
) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "requestDialog: title: {0}, initialValue: {1}",
new Object[]{title, initialValue});
logger.log(
Level.FINE,
"requestDialog: title: {0}, initialValue: {1}",
new Object[] { title, initialValue }
);
}

final View view = JmeAndroidSystem.getView();
view.getHandler().post(new Runnable() {
@Override
public void run() {

final FrameLayout layoutTextDialogInput = new FrameLayout(view.getContext());
final EditText editTextDialogInput = new EditText(view.getContext());
editTextDialogInput.setWidth(LayoutParams.FILL_PARENT);
editTextDialogInput.setHeight(LayoutParams.FILL_PARENT);
editTextDialogInput.setPadding(20, 20, 20, 20);
editTextDialogInput.setGravity(Gravity.FILL_HORIZONTAL);
//editTextDialogInput.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

editTextDialogInput.setText(initialValue);

switch (id) {
case SoftTextDialogInput.TEXT_ENTRY_DIALOG:

editTextDialogInput.setInputType(InputType.TYPE_CLASS_TEXT);
break;

case SoftTextDialogInput.NUMERIC_ENTRY_DIALOG:

editTextDialogInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
break;

case SoftTextDialogInput.NUMERIC_KEYPAD_DIALOG:

editTextDialogInput.setInputType(InputType.TYPE_CLASS_PHONE);
break;

default:
break;
view
.getHandler()
.post(
new Runnable() {
@Override
public void run() {
final FrameLayout layoutTextDialogInput = new FrameLayout(view.getContext());
final EditText editTextDialogInput = new EditText(view.getContext());
editTextDialogInput.setWidth(LayoutParams.FILL_PARENT);
editTextDialogInput.setHeight(LayoutParams.FILL_PARENT);
editTextDialogInput.setPadding(20, 20, 20, 20);
editTextDialogInput.setGravity(Gravity.FILL_HORIZONTAL);
//editTextDialogInput.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

editTextDialogInput.setText(initialValue);

switch (id) {
case SoftTextDialogInput.TEXT_ENTRY_DIALOG:
editTextDialogInput.setInputType(InputType.TYPE_CLASS_TEXT);
break;
case SoftTextDialogInput.NUMERIC_ENTRY_DIALOG:
editTextDialogInput.setInputType(
InputType.TYPE_CLASS_NUMBER |
InputType.TYPE_NUMBER_FLAG_DECIMAL |
InputType.TYPE_NUMBER_FLAG_SIGNED
);
break;
case SoftTextDialogInput.NUMERIC_KEYPAD_DIALOG:
editTextDialogInput.setInputType(InputType.TYPE_CLASS_PHONE);
break;
default:
break;
}

layoutTextDialogInput.addView(editTextDialogInput);

AlertDialog dialogTextInput = new AlertDialog.Builder(view.getContext())
.setTitle(title)
.setView(layoutTextDialogInput)
.setPositiveButton(
"OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK, send COMPLETE action
* and text */
listener.onSoftText(
SoftTextDialogInputListener.COMPLETE,
editTextDialogInput.getText().toString()
);
}
}
)
.setNegativeButton(
"Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked CANCEL, send CANCEL action
* and text */
listener.onSoftText(
SoftTextDialogInputListener.CANCEL,
editTextDialogInput.getText().toString()
);
}
}
)
.create();

dialogTextInput.show();
}
}

layoutTextDialogInput.addView(editTextDialogInput);

AlertDialog dialogTextInput = new AlertDialog.Builder(view.getContext()).setTitle(title).setView(layoutTextDialogInput).setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK, send COMPLETE action
* and text */
listener.onSoftText(SoftTextDialogInputListener.COMPLETE, editTextDialogInput.getText().toString());
}
}).setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked CANCEL, send CANCEL action
* and text */
listener.onSoftText(SoftTextDialogInputListener.CANCEL, editTextDialogInput.getText().toString());
}
}).create();

dialogTextInput.show();
}
});
);
}

@Override
Expand Down Expand Up @@ -542,11 +578,11 @@ public int getWindowXPosition() {
public int getWindowYPosition() {
throw new UnsupportedOperationException("not implemented yet");
}

/**
* Retrieves the dimensions of the input surface. Note: do not modify the
* returned object.
*
*
* @return the dimensions (in pixels, left and top are 0)
*/
private Rect getSurfaceFrame() {
Expand All @@ -555,4 +591,16 @@ private Rect getSurfaceFrame() {
Rect result = holder.getSurfaceFrame();
return result;
}

@Override
public Displays getDisplays() {
// TODO Auto-generated method stub
return null;
}

@Override
public int getPrimaryDisplay() {
// TODO Auto-generated method stub
return 0;
}
}
Loading