forked from StarOpenSource/Engine
Make V-Sync global
This commit is contained in:
parent
e787680e8c
commit
4f9154f5fc
5 changed files with 41 additions and 72 deletions
|
@ -23,6 +23,7 @@ import de.staropensource.sosengine.base.exceptions.UnexpectedThrowableException;
|
||||||
import de.staropensource.sosengine.base.types.Tristate;
|
import de.staropensource.sosengine.base.types.Tristate;
|
||||||
import de.staropensource.sosengine.base.types.vectors.Vec2i;
|
import de.staropensource.sosengine.base.types.vectors.Vec2i;
|
||||||
import de.staropensource.sosengine.base.utility.Miscellaneous;
|
import de.staropensource.sosengine.base.utility.Miscellaneous;
|
||||||
|
import de.staropensource.sosengine.graphics.GraphicsSubsystemConfiguration;
|
||||||
import de.staropensource.sosengine.graphics.classes.Window;
|
import de.staropensource.sosengine.graphics.classes.Window;
|
||||||
import de.staropensource.sosengine.graphics.events.GraphicsApiErrorEvent;
|
import de.staropensource.sosengine.graphics.events.GraphicsApiErrorEvent;
|
||||||
import de.staropensource.sosengine.graphics.events.InputEvent;
|
import de.staropensource.sosengine.graphics.events.InputEvent;
|
||||||
|
@ -89,7 +90,6 @@ public abstract class GlfwWindow extends Window {
|
||||||
* @param maximumSize maximum size
|
* @param maximumSize maximum size
|
||||||
* @param position position
|
* @param position position
|
||||||
* @param windowMode window mode
|
* @param windowMode window mode
|
||||||
* @param vsyncMode V-Sync mode
|
|
||||||
* @param resizable resizable flag
|
* @param resizable resizable flag
|
||||||
* @param borderless borderless flag
|
* @param borderless borderless flag
|
||||||
* @param focusable focusable flag
|
* @param focusable focusable flag
|
||||||
|
@ -99,8 +99,8 @@ public abstract class GlfwWindow extends Window {
|
||||||
* @throws UnexpectedThrowableException stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing Graphics API
|
* @throws UnexpectedThrowableException stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing Graphics API
|
||||||
* @since v1-alpha2
|
* @since v1-alpha2
|
||||||
*/
|
*/
|
||||||
public GlfwWindow(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, @NotNull VsyncMode vsyncMode, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws UnexpectedThrowableException {
|
public GlfwWindow(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws UnexpectedThrowableException {
|
||||||
super(name, title, size, minimumSize, maximumSize, position, windowMode, vsyncMode, resizable, borderless, focusable, onTop, transparent, rendering);
|
super(name, title, size, minimumSize, maximumSize, position, windowMode, resizable, borderless, focusable, onTop, transparent, rendering);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@ -162,7 +162,7 @@ public abstract class GlfwWindow extends Window {
|
||||||
ownContext();
|
ownContext();
|
||||||
|
|
||||||
// Set swap interval based on V-Sync mode setting
|
// Set swap interval based on V-Sync mode setting
|
||||||
glfwSwapInterval(getVsyncMode() == VsyncMode.ON ? 1 : 0);
|
glfwSwapInterval(GraphicsSubsystemConfiguration.getInstance().getVsyncMode() == VsyncMode.ON ? 1 : 0);
|
||||||
|
|
||||||
// Create callbacks
|
// Create callbacks
|
||||||
keyCallback = GLFWKeyCallback.create(new KeyCallback(this));
|
keyCallback = GLFWKeyCallback.create(new KeyCallback(this));
|
||||||
|
|
|
@ -49,7 +49,6 @@ public class OpenGlWindow extends GlfwWindow {
|
||||||
* @param maximumSize maximum size
|
* @param maximumSize maximum size
|
||||||
* @param position position
|
* @param position position
|
||||||
* @param windowMode window mode
|
* @param windowMode window mode
|
||||||
* @param vsyncMode V-Sync mode
|
|
||||||
* @param resizable resizable flag
|
* @param resizable resizable flag
|
||||||
* @param borderless borderless flag
|
* @param borderless borderless flag
|
||||||
* @param focusable focusable flag
|
* @param focusable focusable flag
|
||||||
|
@ -59,8 +58,8 @@ public class OpenGlWindow extends GlfwWindow {
|
||||||
* @throws UnexpectedThrowableException stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing Graphics API
|
* @throws UnexpectedThrowableException stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing Graphics API
|
||||||
* @since v1-alpha2
|
* @since v1-alpha2
|
||||||
*/
|
*/
|
||||||
public OpenGlWindow(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, @NotNull VsyncMode vsyncMode, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws UnexpectedThrowableException {
|
public OpenGlWindow(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws UnexpectedThrowableException {
|
||||||
super(name, title, size, minimumSize, maximumSize, position, windowMode, vsyncMode, resizable, borderless, focusable, onTop, transparent, rendering);
|
super(name, title, size, minimumSize, maximumSize, position, windowMode, resizable, borderless, focusable, onTop, transparent, rendering);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
|
@ -25,6 +25,7 @@ import de.staropensource.sosengine.base.types.CodePart;
|
||||||
import de.staropensource.sosengine.base.types.logging.LogIssuer;
|
import de.staropensource.sosengine.base.types.logging.LogIssuer;
|
||||||
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
|
import de.staropensource.sosengine.base.utility.parser.PropertyParser;
|
||||||
import de.staropensource.sosengine.graphics.events.GraphicsErrorEvent;
|
import de.staropensource.sosengine.graphics.events.GraphicsErrorEvent;
|
||||||
|
import de.staropensource.sosengine.graphics.types.window.VsyncMode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -128,7 +129,25 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat
|
||||||
private boolean errorGraphicsError;
|
private boolean errorGraphicsError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines how many frames can be rendered max per second.
|
* Determines how many frames can be rendered per second.
|
||||||
|
* <p>
|
||||||
|
* This setting determines if and how V-Sync will operate, which
|
||||||
|
* (if enabled) tries to synchronize the frame rate to the monitor's
|
||||||
|
* refresh rate. See {@link VsyncMode} for more information.
|
||||||
|
*
|
||||||
|
* @since v1-alpha2
|
||||||
|
*
|
||||||
|
* -- GETTER --
|
||||||
|
* Gets the value for {@link #vsyncMode}.
|
||||||
|
*
|
||||||
|
* @return variable value
|
||||||
|
* @see #vsyncMode
|
||||||
|
* @since v1-alpha2
|
||||||
|
*/
|
||||||
|
private VsyncMode vsyncMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines how many frames can be rendered per second.
|
||||||
* <p>
|
* <p>
|
||||||
* This value will have no effect on windows with V-Sync enabled.
|
* This value will have no effect on windows with V-Sync enabled.
|
||||||
* Set to {@code 0} for no limit.
|
* Set to {@code 0} for no limit.
|
||||||
|
@ -136,7 +155,7 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat
|
||||||
* @since v1-alpha2
|
* @since v1-alpha2
|
||||||
*
|
*
|
||||||
* -- GETTER --
|
* -- GETTER --
|
||||||
* Gets the value for {@link #maximumFramesPerSecond}
|
* Gets the value for {@link #maximumFramesPerSecond}.
|
||||||
*
|
*
|
||||||
* @return variable value
|
* @return variable value
|
||||||
* @see #maximumFramesPerSecond
|
* @see #maximumFramesPerSecond
|
||||||
|
@ -181,6 +200,13 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat
|
||||||
|
|
||||||
case "errorGraphicsError" -> errorGraphicsError = parser.getBoolean(group + property);
|
case "errorGraphicsError" -> errorGraphicsError = parser.getBoolean(group + property);
|
||||||
|
|
||||||
|
case "vsyncMode" -> {
|
||||||
|
try {
|
||||||
|
vsyncMode = VsyncMode.valueOf(parser.getString(group + property).toUpperCase());
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
Logger.error(new LogIssuer(getClass(), CodePart.ENGINE), "V-Sync mode " + parser.getString(group + property) + " is not valid");
|
||||||
|
}
|
||||||
|
}
|
||||||
case "maximumFramesPerSecond" -> maximumFramesPerSecond = parser.getInteger(group + property, true);
|
case "maximumFramesPerSecond" -> maximumFramesPerSecond = parser.getInteger(group + property, true);
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ignored) {}
|
} catch (NullPointerException ignored) {}
|
||||||
|
@ -206,7 +232,8 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat
|
||||||
|
|
||||||
errorGraphicsError = true;
|
errorGraphicsError = true;
|
||||||
|
|
||||||
maximumFramesPerSecond = 60;
|
vsyncMode = VsyncMode.OFF;
|
||||||
|
maximumFramesPerSecond = 120;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
@ -219,6 +246,7 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat
|
||||||
|
|
||||||
case "errorGraphicsError" -> { return errorGraphicsError; }
|
case "errorGraphicsError" -> { return errorGraphicsError; }
|
||||||
|
|
||||||
|
case "vsyncMode" -> { return vsyncMode; }
|
||||||
case "maximumFramesPerSecond" -> { return maximumFramesPerSecond; }
|
case "maximumFramesPerSecond" -> { return maximumFramesPerSecond; }
|
||||||
default -> { return null; }
|
default -> { return null; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,9 @@ import de.staropensource.sosengine.base.exceptions.UnexpectedThrowableException;
|
||||||
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
import de.staropensource.sosengine.base.logging.LoggerInstance;
|
||||||
import de.staropensource.sosengine.base.types.CodePart;
|
import de.staropensource.sosengine.base.types.CodePart;
|
||||||
import de.staropensource.sosengine.base.types.Tristate;
|
import de.staropensource.sosengine.base.types.Tristate;
|
||||||
import de.staropensource.sosengine.base.types.immutable.ImmutableHashSet;
|
|
||||||
import de.staropensource.sosengine.base.types.logging.LogIssuer;
|
import de.staropensource.sosengine.base.types.logging.LogIssuer;
|
||||||
import de.staropensource.sosengine.base.types.vectors.Vec2i;
|
import de.staropensource.sosengine.base.types.vectors.Vec2i;
|
||||||
import de.staropensource.sosengine.graphics.GraphicsSubsystem;
|
import de.staropensource.sosengine.graphics.GraphicsSubsystem;
|
||||||
import de.staropensource.sosengine.graphics.types.window.VsyncMode;
|
|
||||||
import de.staropensource.sosengine.graphics.types.window.WindowMode;
|
import de.staropensource.sosengine.graphics.types.window.WindowMode;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -319,27 +317,6 @@ public abstract class Window implements AutoCloseable {
|
||||||
@Setter
|
@Setter
|
||||||
private WindowMode windowMode;
|
private WindowMode windowMode;
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines the V-Sync mode this window targets.
|
|
||||||
*
|
|
||||||
* @since v1-alpha2
|
|
||||||
*
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the V-Sync mode.
|
|
||||||
*
|
|
||||||
* @return V-Sync mode
|
|
||||||
* @since v1-alpha2
|
|
||||||
*
|
|
||||||
* -- SETTER --
|
|
||||||
* Sets the V-Sync mode.
|
|
||||||
*
|
|
||||||
* @param vsyncMode new vsync mode
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
@Setter
|
|
||||||
private VsyncMode vsyncMode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines how fast the window may update it's contents.
|
* Determines how fast the window may update it's contents.
|
||||||
*
|
*
|
||||||
|
@ -508,7 +485,6 @@ public abstract class Window implements AutoCloseable {
|
||||||
* @param maximumSize maximum size
|
* @param maximumSize maximum size
|
||||||
* @param position position
|
* @param position position
|
||||||
* @param windowMode window mode
|
* @param windowMode window mode
|
||||||
* @param vsyncMode V-Sync mode
|
|
||||||
* @param resizable resizable flag
|
* @param resizable resizable flag
|
||||||
* @param borderless borderless flag
|
* @param borderless borderless flag
|
||||||
* @param focusable focusable flag
|
* @param focusable focusable flag
|
||||||
|
@ -518,8 +494,8 @@ public abstract class Window implements AutoCloseable {
|
||||||
* @throws UnexpectedThrowableException stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing Graphics API
|
* @throws UnexpectedThrowableException stuff thrown by the {@link #initializeWindow()} and {@link #render()} methods of the implementing Graphics API
|
||||||
* @since v1-alpha2
|
* @since v1-alpha2
|
||||||
*/
|
*/
|
||||||
public Window(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, @NotNull VsyncMode vsyncMode, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws UnexpectedThrowableException {
|
public Window(@NotNull String name, @NotNull String title, @NotNull Vec2i size, @NotNull Vec2i minimumSize, @NotNull Vec2i maximumSize, @NotNull Vec2i position, @NotNull WindowMode windowMode, boolean resizable, boolean borderless, boolean focusable, boolean onTop, boolean transparent, boolean rendering) throws UnexpectedThrowableException {
|
||||||
logger.diag("Creating new window with properties: name=\"" + name + "\" title=\"" + title + "\" size=" + size + " minimumSize=" + minimumSize + " maximumSize=" + maximumSize + " position=" + position + " windowMode=" + windowMode + " vsyncMode=" + vsyncMode + " resizable=" + resizable + " borderless=" + borderless + " focusable=" + focusable + " onTop=" + onTop + " transparent=" + transparent + " rendering=" + rendering);
|
logger.diag("Creating new window with properties: name=\"" + name + "\" title=\"" + title + "\" size=" + size + " minimumSize=" + minimumSize + " maximumSize=" + maximumSize + " position=" + position + " windowMode=" + windowMode + " resizable=" + resizable + " borderless=" + borderless + " focusable=" + focusable + " onTop=" + onTop + " transparent=" + transparent + " rendering=" + rendering);
|
||||||
|
|
||||||
// Initialize variables
|
// Initialize variables
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -529,7 +505,6 @@ public abstract class Window implements AutoCloseable {
|
||||||
this.maximumSize = maximumSize;
|
this.maximumSize = maximumSize;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.windowMode = windowMode;
|
this.windowMode = windowMode;
|
||||||
this.vsyncMode = vsyncMode;
|
|
||||||
this.resizable = resizable;
|
this.resizable = resizable;
|
||||||
this.borderless = borderless;
|
this.borderless = borderless;
|
||||||
this.focusable = focusable;
|
this.focusable = focusable;
|
||||||
|
@ -777,22 +752,6 @@ public abstract class Window implements AutoCloseable {
|
||||||
@Nullable
|
@Nullable
|
||||||
private WindowMode windowMode = null;
|
private WindowMode windowMode = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains the V-Sync mode.
|
|
||||||
*
|
|
||||||
* @see Window#vsyncMode
|
|
||||||
* @since v1-alpha2
|
|
||||||
*
|
|
||||||
* -- GETTER --
|
|
||||||
* Returns the V-Sync mode.
|
|
||||||
*
|
|
||||||
* @return V-Sync mode
|
|
||||||
* @see Window#vsyncMode
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
private VsyncMode vsyncMode = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the resizable flag.
|
* Contains the resizable flag.
|
||||||
*
|
*
|
||||||
|
@ -929,8 +888,6 @@ public abstract class Window implements AutoCloseable {
|
||||||
maximumSize = new Vec2i(-1, -1);
|
maximumSize = new Vec2i(-1, -1);
|
||||||
if (windowMode == null)
|
if (windowMode == null)
|
||||||
windowMode = WindowMode.WINDOWED;
|
windowMode = WindowMode.WINDOWED;
|
||||||
if (vsyncMode == null)
|
|
||||||
vsyncMode = VsyncMode.ON;
|
|
||||||
|
|
||||||
// Override booleanized tristate defaults
|
// Override booleanized tristate defaults
|
||||||
if (resizable == Tristate.FALSE)
|
if (resizable == Tristate.FALSE)
|
||||||
|
@ -949,8 +906,8 @@ public abstract class Window implements AutoCloseable {
|
||||||
// Create new Window instance
|
// Create new Window instance
|
||||||
try {
|
try {
|
||||||
return GraphicsSubsystem.getInstance().getApi().getInternalApi().getWindowClass()
|
return GraphicsSubsystem.getInstance().getApi().getInternalApi().getWindowClass()
|
||||||
.getDeclaredConstructor(String.class, String.class, Vec2i.class, Vec2i.class, Vec2i.class, Vec2i.class, WindowMode.class, VsyncMode.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE)
|
.getDeclaredConstructor(String.class, String.class, Vec2i.class, Vec2i.class, Vec2i.class, Vec2i.class, WindowMode.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE)
|
||||||
.newInstance(name, title, size, minimumSize, maximumSize, position, windowMode, vsyncMode, resizableBoolean, borderlessBoolean, focusableBoolean, onTopBoolean, transparentBoolean, renderingBoolean);
|
.newInstance(name, title, size, minimumSize, maximumSize, position, windowMode, resizableBoolean, borderlessBoolean, focusableBoolean, onTopBoolean, transparentBoolean, renderingBoolean);
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
throw new UnexpectedThrowableException(throwable, "Window.Builder was unable to create new Window instance");
|
throw new UnexpectedThrowableException(throwable, "Window.Builder was unable to create new Window instance");
|
||||||
}
|
}
|
||||||
|
@ -1047,19 +1004,6 @@ public abstract class Window implements AutoCloseable {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the V-Sync mode.
|
|
||||||
*
|
|
||||||
* @param vsyncMode new V-Sync mode
|
|
||||||
* @return builder instance
|
|
||||||
* @since v1-alpha2
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public synchronized Builder setVsyncMode(@Nullable VsyncMode vsyncMode) {
|
|
||||||
this.vsyncMode = vsyncMode;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the resizable flag.
|
* Sets the resizable flag.
|
||||||
*
|
*
|
||||||
|
|
|
@ -42,7 +42,6 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The initialization class for sos!engine's development application.
|
* The initialization class for sos!engine's development application.
|
||||||
|
@ -139,7 +138,6 @@ public class Main {
|
||||||
.setTitle("test application window")
|
.setTitle("test application window")
|
||||||
.setSize(new Vec2i(960, 540))
|
.setSize(new Vec2i(960, 540))
|
||||||
.setPosition(new Vec2i(10, 10))
|
.setPosition(new Vec2i(10, 10))
|
||||||
.setVsyncMode(VsyncMode.OFF)
|
|
||||||
.build();
|
.build();
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
logger.crash("Window.Builder#build() failed", throwable);
|
logger.crash("Window.Builder#build() failed", throwable);
|
||||||
|
|
Loading…
Reference in a new issue