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 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
import com.jme3.renderer.opengl.*;
import com.jme3.system.*;
import com.jme3.util.BufferAllocatorFactory;
import com.jme3.util.AndroidNativeBufferAllocator;
import com.jme3.util.PrimitiveAllocator;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -85,7 +86,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
final String implementation = BufferAllocatorFactory.PROPERTY_BUFFER_ALLOCATOR_IMPLEMENTATION;

if (System.getProperty(implementation) == null) {
System.setProperty(implementation, AndroidNativeBufferAllocator.class.getName());
System.setProperty(implementation, PrimitiveAllocator.class.getName());
}
}

Expand Down Expand Up @@ -554,4 +555,18 @@ private Rect getSurfaceFrame() {
Rect result = holder.getSurfaceFrame();
return result;
}

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

@Override
public int getPrimaryMonitor()
{
// TODO Auto-generated method stub
return 0;
}
}
24 changes: 24 additions & 0 deletions jme3-core/src/main/java/com/jme3/app/LegacyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -852,4 +852,28 @@ public Object call() {
return null;
}
}

/**
* This call will return a list of Monitors that glfwGetMonitors()
* returns and information about the monitor, like width, height,
* and refresh rate.
*
* @return returns a list of monitors and their information.
*/
public Monitors getMonitors()
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Kevin, thanks for this work, according to the Google style of code (that we are following here), the curly brackets of a code block shouldn't be on a new line, so please, Can you refactor the K&R bracket style to Java Style on all the code involved in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure no problem

return context.getMonitors();
}

/**
* Use this to get the positional number of the primary
* monitor from the glfwGetMonitors() function call.
*
* @return the position of the value in the arraylist of
* the primary monitor.
*/
public int getPrimaryMonitor()
{
return context.getPrimaryMonitor();
}
}
29 changes: 29 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public final class AppSettings extends HashMap<String, Object> {
public static final String JOAL = "JOAL";

static {
defaults.put("Monitor", 0);
defaults.put("CenterWindow", true);
defaults.put("Width", 640);
defaults.put("Height", 480);
Expand Down Expand Up @@ -1479,4 +1480,32 @@ public int getWindowYPosition() {
public void setWindowYPosition(int pos) {
putInteger("WindowYPosition", pos);
}


/**
* Gets the monitor number used when creating a window.
*
* <p>This setting is used only with LWJGL3, it defines which monitor
* to use when creating a OpenGL window.
*
* @return the desired monitor used when creating a OpenGL window
* @see #setMonitor(long)
*/
public int getMonitor() {
return getInteger("Monitor");
Copy link
Contributor

@pavly-gerges pavly-gerges Jun 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to wrap the "Monitor" string key in a constant object for future refactoring and testing purposes, you can use the MonitorInfo to define default static Keys there.

}

/**
* Sets the monitor number used when creating a window. The position
* number is the number in the list of monitors GlfwGetMonitors returns.
*
* <p>This setting is used only with LWJGL3, it defines which monitor
* to use when creating a OpenGL window. its default value is 0.
*
* @param mon the desired monitor used when creating a OpenGL window
*
*/
public void setMonitor(int mon) {
putInteger("Monitor", mon);
}
}
18 changes: 18 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/JmeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,22 @@ public enum Type {
* @throws IllegalStateException for a headless or null context
*/
public int getWindowYPosition();

/**
* This call will return a list of Monitors that glfwGetMonitors()
* returns and information about the monitor, like width, height,
* and refresh rate.
*
* @return returns a list of monitors and their information.
*/
public Monitors getMonitors();

/**
* Use this to get the positional number of the primary
* monitor from the glfwGetMonitors() function call.
*
* @return the position of the value in the arraylist of
* the primary monitor.
*/
public int getPrimaryMonitor();
}
73 changes: 73 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/MonitorInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2009-2023 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.system;

/**
* This class holds information about the monitor that was
* returned by glfwGetMonitors() calls in the context
* class
*
* @author Kevin Bales
*/
public class MonitorInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be marked as final, and I don't know if it needs to use the conventional style of getters and setters since their advantage here is not very obvious, but I think encapsulation should be the rule here, in case direct changes need to be applied to the member variables in the future.


/**
* monitorID - monitor id that was return from Lwjgl3.
*/
public long monitorID = 0;

/**
* width - width that was return from Lwjgl3.
*/
public int width = 1080;

/**
* height - height that was return from Lwjgl3.
*/
public int height = 1920;

/**
* rate - refresh rate that was return from Lwjgl3.
*/
public int rate = 60;

/**
* primary - indicates if the monitor is the primary monitor.
*/
public boolean primary = false;

/**
* name - monitor name that was return from Lwjgl3.
*/
public String name = "Generic Monitor";

}
119 changes: 119 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/Monitors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* Copyright (c) 2009-2023 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.system;

import java.util.ArrayList;

/**
* This class holds all information about all monitors that where
* return from the glfwGetMonitors() call. It stores them into
* an <ArrayList>
*
* @author Kevin Bales
*/
public class Monitors {

private ArrayList<MonitorInfo> monitors = new ArrayList<MonitorInfo>();

public int addNewMonitor(long monitorID)
{
MonitorInfo info = new MonitorInfo();
info.monitorID = monitorID;
monitors.add(info);
return monitors.size() - 1;
}

/**
* This function returns the size of the monitor ArrayList
* @return the
*/
public int size()
{
return monitors.size();
}

/**
* Call to get monitor information on a certain monitor.
*
* @param pos the position in the arraylist of the monitor
* information that you want to get.
* @return returns the MonitorInfo data for the monitor
* called for.
*/
public MonitorInfo get(int pos)
{
if (pos < monitors.size())
return monitors.get(pos);

return null;
}

/**
* Set information about this monitor stored in monPos position
* in the array list.
*
* @param monPos arraylist position of monitor to update
* @param width the current width the monitor is displaying
* @param height the current height the monitor is displaying
* @param rate the current refresh rate the monitor is set to
*/
public void setInfo(int monPos, String name, int width, int height, int rate) {
if (monPos < monitors.size() ) {
MonitorInfo info = monitors.get(monPos);
if (info != null) {
info.width = width;
info.height = height;
info.rate = rate;
info.name = name;
}
}
}

/**
* This function will mark a certain monitor as the
* primary monitor.
*
* @param monPos the position in the arraylist of which
* monitor is the primary monitor
*/
public void setPrimaryMonitor(int monPos) {
if (monPos < monitors.size() ) {
MonitorInfo info = monitors.get(monPos);
if (info != null)
info.primary = true;
}

}



}
12 changes: 12 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/NullContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,16 @@ public int getWindowXPosition() {
public int getWindowYPosition() {
throw new UnsupportedOperationException("null context");
}

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

@Override
public int getPrimaryMonitor() {
// TODO Auto-generated method stub
return 0;
}
}
12 changes: 12 additions & 0 deletions jme3-desktop/src/main/java/com/jme3/system/AWTContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,16 @@ public int getWindowXPosition() {
public int getWindowYPosition() {
throw new UnsupportedOperationException("not implemented yet");
}

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

@Override
public int getPrimaryMonitor() {
// TODO Auto-generated method stub
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,16 @@ public int getWindowXPosition() {
public int getWindowYPosition() {
return inputSource.getY();
}

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

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