Update graphics subsystem and OpenGL API

This commit is contained in:
JeremyStar™ 2024-06-15 22:24:37 +02:00
parent bae7b4c337
commit 51e0f84c3f
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
4 changed files with 73 additions and 7 deletions

View file

@ -30,7 +30,7 @@ import org.jetbrains.annotations.NotNull;
* @since 1-alpha0 * @since 1-alpha0
*/ */
@SuppressWarnings({ "unused" }) @SuppressWarnings({ "unused" })
public class OpenGlManagement implements ApiManagementClass { public final class OpenGlManagement implements ApiManagementClass {
/** {@inheritDoc} */ /** {@inheritDoc} */
@NotNull @NotNull
@Override @Override

View file

@ -21,12 +21,14 @@ package de.staropensource.sosengine.graphics.opengl;
import de.staropensource.sosengine.base.annotations.EventListener; import de.staropensource.sosengine.base.annotations.EventListener;
import de.staropensource.sosengine.base.classes.EventPriority; import de.staropensource.sosengine.base.classes.EventPriority;
import de.staropensource.sosengine.base.classes.helpers.EventHelper;
import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.types.LogIssuer; import de.staropensource.sosengine.base.types.LogIssuer;
import de.staropensource.sosengine.base.utility.Miscellaneous; import de.staropensource.sosengine.base.utility.Miscellaneous;
import de.staropensource.sosengine.graphics.GraphicsSubsystem; import de.staropensource.sosengine.graphics.GraphicsSubsystem;
import de.staropensource.sosengine.graphics.classes.ApiMainClass; import de.staropensource.sosengine.graphics.classes.ApiMainClass;
import de.staropensource.sosengine.graphics.classes.ApiManagementClass; import de.staropensource.sosengine.graphics.classes.ApiManagementClass;
import de.staropensource.sosengine.graphics.events.GraphicsApiErrorEvent;
import de.staropensource.sosengine.graphics.opengl.events.GraphicsErrorEvent; import de.staropensource.sosengine.graphics.opengl.events.GraphicsErrorEvent;
import lombok.Getter; import lombok.Getter;
import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.GLFWErrorCallback;
@ -88,10 +90,15 @@ public final class OpenGlSubsystem implements ApiMainClass {
instance.logger.crash("The subsystem tried to initialize twice"); instance.logger.crash("The subsystem tried to initialize twice");
} }
// Register Graphics API long initTime = Miscellaneous.measureExecutionTime(() -> {
GraphicsSubsystem.getInstance().registerGraphicsApi(this); // Precompute event listeners
EventHelper.precomputeEventListeners(GraphicsErrorEvent.class);
logger.info("Initialized subsystem"); // Register Graphics API
GraphicsSubsystem.getInstance().registerGraphicsApi(this);
});
logger.info("Initialized subsystem in " + initTime + "ms");
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@ -140,14 +147,25 @@ public final class OpenGlSubsystem implements ApiMainClass {
} }
/** /**
* Called when a graphics error occurs. This method just logs the error and returns. * Called when an OpenGL error occurs. This method just logs the error and returns.
* *
* @param error graphics error * @param error graphics error
* @since 1-alpha0 * @since 1-alpha0
*/ */
@EventListener(event = GraphicsErrorEvent.class, priority = EventPriority.EXTREMELY_IMPORTANT) @EventListener(event = GraphicsErrorEvent.class, priority = EventPriority.EXTREMELY_IMPORTANT)
public static void onGraphicsError(String error) { public static void onGraphicsError(String error) {
instance.logger.error("An error occurred: " + error); instance.logger.error("OpenGL returned an error: " + error);
}
/**
* Called when a Graphics API error occurs. This method just logs the error and returns.
*
* @param error Graphics API error
* @since 1-alpha0
*/
@EventListener(event = GraphicsApiErrorEvent.class, priority = EventPriority.EXTREMELY_IMPORTANT)
public static void onGraphicsApiError(String error) {
instance.logger.error("Graphics API returned an error: " + error);
} }
/** /**

View file

@ -33,7 +33,6 @@ import de.staropensource.sosengine.graphics.events.GraphicsApiShutdownEvent;
import de.staropensource.sosengine.graphics.events.GraphicsErrorEvent; import de.staropensource.sosengine.graphics.events.GraphicsErrorEvent;
import lombok.Getter; import lombok.Getter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;

View file

@ -0,0 +1,49 @@
package de.staropensource.sosengine.graphics.events;
import de.staropensource.sosengine.base.classes.Event;
import de.staropensource.sosengine.base.events.LogEvent;
import de.staropensource.sosengine.base.types.LogIssuer;
import de.staropensource.sosengine.base.types.LogLevel;
import de.staropensource.sosengine.base.classes.helpers.EventHelper;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Called when a graphics error occurs.
*
* @since 1-alpha0
*/
@SuppressWarnings({ "unused" })
public class GraphicsApiErrorEvent implements Event {
/**
* Constructor.
*/
public GraphicsApiErrorEvent() {}
/**
* {@inheritDoc}
* @deprecated use the {@code callEvent} method with arguments
* @see LogEvent#callEvent(LogLevel, LogIssuer, String)
*/
@Deprecated
@Override
public void callEvent() {}
/**
* Calls the event and notifies all annotated methods.
*
* @param error graphics error
* @since 1-alpha0
*/
public void callEvent(@NotNull String error) {
EventHelper.logCall(getClass());
for (Method method : EventHelper.getAnnotatedMethods(getClass())) {
try {
method.invoke(null, error);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NullPointerException | ExceptionInInitializerError ignored) {}
}
}
}